Hey I am trying to output, a serial.read() from a RFID reader to a string, so I can output i to a client.print.
if I do Serial.print(Serial.read()); it looks okey, in arduino serial monitor, but if I use client.print, it do not work.
I have tried this
char recieved =(char)Serial.read();
inData += recieved;
Serial.print(inData);
it should look like this 0A007AA1AC but all I am getting is ž Ï ò µ and all other signs, and very random.
Do I need som kind of convertion, to understand the output from the serial.read()
#include <Ethernet.h>
#include <SPI.h>
byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x31 };
char SH_serial;
char inData;
EthernetClient client;
char server[] = "92.144.244.134";
int interval = 100;
/*function for serial conn*/
int readline(int readch, char *buffer, int len){
static int pos = 0;
int rpos;
if (readch > 0) {
switch (readch) {
case '\n': // Ignore new-lines
break;
case '\r': // Return on CR
rpos = pos;
pos = 0; // Reset position index ready for next time
return rpos;
default:
if (pos < len-1) {
buffer[pos++] = readch;
buffer[pos] = 0;
}
}
}
// No end of line has been found, so return -1.
return -1;
}
void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
Serial.print("IP Address : ");
Serial.println(Ethernet.localIP());
Serial.print("Subnet Mask : ");
Serial.println(Ethernet.subnetMask());
Serial.print("Default Gateway IP: ");
Serial.println(Ethernet.gatewayIP());
Serial.print("DNS Server IP : ");
Serial.println(Ethernet.dnsServerIP());
}
void loop() {
// if you get a connection, report back via serial:
static char buffer[12];
//det er her vores funktion, som gøre rent i serial kommunikation
if (readline(Serial.read(), buffer, 12) > 0) {
//her sender vi koden over i en variable, som jeg sender til php og mysql
//serveren med client.print, jeg skal havde lave et eller andet som buffer/
//samler teksten op, inden den bliver sendt til serveren, måske skal det være to
//adskildte funktioner.w
SH_serial = Serial.read();
// inData is used in client.print at end of script
char recieved =(char)Serial.read();
inData += recieved;
Serial.print(inData);
if (client.connect(server, 80)) {
//Serial.println("-> Connected");
// Make a HTTP request:
//inData goes here
client.print( "GET http://host.dk/anders/arduino_door/add_data.php?");
client.print("serial=");
client.print(inData);
client.print("&&");
client.print("temperature=");
client.print( "12.3" );
client.println( " HTTP/1.1");
client.print( "Host: " );
client.println(server);
client.println( "Connection: close" );
client.println();
client.println();
client.stop();
}
else {
Serial.println("--> connection failed/n");
}
}
}