Tillbaka till forum

Arduino fråga

2018-04-25 21:29:41 av patrikpatrik
Hej, hur skriver man frågan i arduino? Jag trodde jag bara kunde stoppa in XML frågan som en lång text fil i "XXXX" nedan, men det fungerade inte alls - jag fick bara detta svar <RESPONSE> <RESULT> <ERROR>Unsupported request content type</ERROR> </RESULT> </RESPONSE> #include <ESP8266HTTPClient.h> #include <ESP8266WiFi.h> const char* ssid = "xxx"; const char* password = "yyy"; void setup() { Serial.begin(115200); //Serial connection WiFi.begin(ssid, password); //WiFi connection while (WiFi.status() != WL_CONNECTED) { //Wait for the WiFI connection completion delay(500); Serial.println("Waiting for connection"); } } void loop() { if(WiFi.status()== WL_CONNECTED){ //Check WiFi connection status HTTPClient http; //Declare object of class HTTPClient http.begin("http://api.trafikinfo.trafikverket.se/v1.3/data.json"); //Specify request destination http.addHeader("Content-Type", "text/plain"); //Specify content-type header int httpCode = http.POST("XXXX"); //Send the request String payload = http.getString(); //Get the response payload Serial.println(httpCode); //Print HTTP return code Serial.println(payload); //Print request response payload http.end(); //Close connection }else{ Serial.println("Error in WiFi connection"); } delay(30000); //Send a request every 30 seconds } jag ersatte XXX med: int httpCode = http.POST("<REQUEST> <LOGIN authenticationkey=\"xxxxxxxxxxxxxxxxxxx\" /> <QUERY objecttype=\"Situation\"> <FILTER> <EQ name=\"Deviation.MessageType\" value=\"Olycka\" /> </FILTER> <INCLUDE>Deviation.Id</INCLUDE> <INCLUDE>Deviation.Header</INCLUDE> <INCLUDE>Deviation.IconId</INCLUDE> <INCLUDE>Deviation.Geometry.WGS84</INCLUDE> </QUERY> </REQUEST>"); //Send the request
Svara