We have been trying to get a Mega2560 using a WINC1500 WiFi adapter to post data from a capacitive sensor to a Express JS/Node.js server.
We have only been able to get it to post values that are coming through as [object Object] or undefined.
Have tried using JSON.stringify in the server and using application/json as the type. Have tried formatting the data as a JSON string and as plain strings etc etc.
Does anyone have any ideas of what we could be doing wrong? I'll attach the post method and the whole sketch below as well as the example file I have been following.
String postSession(String touchL, String touchR){
String id = "";
String postData = "{\n\t\"patientID\": \"3277127\",\n\t\"capacitiveFeedL\": \"1200 1500\",\n\t\"capacitiveFeedR\": \"1200 1500\"\n}";
//= "{\"patientID\":\"" + cardString + "\",\"capacitiveFeedL\":\"" + touchL + "\",\"capacitiveFeedR\":\"" + touchR + "\"}";
Serial.println("Posting: " + postData);
delay(100);
Serial.println(postData.length());
delay(100);
if (client.connect(server, 8080)){
client.println("POST /api/session HTTP/1.1");
client.println("Host: 192.168.43.78:8080");
client.println("Content-Type: text/plain;");
client.print("Content-Length: ");
client.println(postData.length() + "\r\n\r\n");
client.println();
client.println(postData);
delay(1000);
client.flush();
client.stop();
//GET SESSIONID FROM POST RETURN
return id;
}
}
Arduino_MySQL_080518.ino (7.05 KB)
PostExample.ino (1.27 KB)