snazim sa komunikovat s externym zariadenim cez LAN a http server/client, POST metodou.
Data (url a data) mu poslem cez seriovu linku, tie nasledne ukladam do String premennych RSurl a RSdata.
Stane sa vsak nieco mne nezname a v momente, ked chcem spustit POST prikaz a pouzit tieto dva stringy, RSurl je "pokazeny" a teda cielove zariadenie(server) mi vrati spravu, ze nepozna prikaz.
Mozno sa podobny problem tyka aj stringu RSdata, ale ten je kratky a nateraz som nevypozoroval divne spravanie.
Preto sa chcem spytat, co sa tam moze diat, ze sa tento string pokazi?
Problem je pritomny v Arduino Nano V3 (Atmega 328p), pricom Arduino Mega 2560 s tym nema problem a funguje s tym istym softwarom korektne.
Dakujem za rady.
Cast kodu:
Kód: Vybrať všetko
void serialEvent() {
String RS="";
int c=0;
delayMicroseconds(3000);
while (Serial.available() > 0) {
char inChar = (char)Serial.read();
RS += inChar;
if (inChar == '\n') { RS=RS.substring(0,RS.length()-1);}
}
if(RS.substring(0,8)=="POSTURL ") {
RSurl="";
while(c<RS.length()-8) { RSurl+=RS[8+c];c++;}
Serial.println("POST URL: "+RSurl);
}
if(RS.substring(0,9)=="POSTDATA ") {
RSdata="";
while(c<RS.length()-9) { RSdata+=RS[9+c];c++;}
Serial.println("POST DATA: "+RSdata);
}
if(RS.substring(0,12)=="POST REQUEST") {
Serial.println("POST COMMAND SENT");
// RSurl="http://192.168.10.101/Services/GetWeldResult";
// RSdata="{\"Sid\":12345}";
Serial.println("Kontrola URL: "+RSurl);
Serial.println("Kontrola DATA: "+RSdata);
Serial.println("...");
POSTrequest(RSurl,RSdata);
}
Serial.flush();
}
Najprv mu poslem z terminalu POSTURL ---, cim nastavi RSurl string.
Potom poslem POSTDATA ---, nastavi RSdata string,
Nakoniec to odstartujem prikazom POST REQUEST
Kód: Vybrať všetko
Initialize Ethernet with DHCP:
Connecting to 192.168.10.101...
Connected to 192.168.10.101
POST URL: http://192.168.10.101/Services/GetWeldResult
POST DATA: {"Sid":12345}
POST COMMAND SENT
Kontrola URL: http://192.168.10.101/Services/Geö Result
Kontrola DATA: {"Sid":12345}
...
Response:
>>>
HTTP/1.1 404 Not Found
Content-Length: 122
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
<html><head><title>Firmware Upload</title></head><body><h2>Server Message:</h2>URL Not found. 192.168.10.101</body></html>
<