I’ve been able to send a packet with the correct structure using the Chrome Extension Advanced Rest Client, but I haven’t been able to duplicate the success with the Core itself. Can anyone point at any differences between the two that might cause the Spark Core one to not work?
Here is the packet that is sent via the Chrome extension(and works) to this host http://10.0.0.1:10000/sony/camera
POST /sony/camera HTTP/1.1
Host: 10.0.0.1:10000
Connection: keep-alive
Content-Length: 66
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36
Origin: chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
Content-Type: application/json-rpc
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8
{"method": "actTakePicture","params": [],"id": 1,"version": "1.0"}
Here is the packet I’ve been sending with the Spark Core(does not work)
POST /sony/camera HTTP/1.1
Host:10.0.0.1:10000
Accept:*/*
Content-Length: 72
Content-Type: application/json-rpc
{"method": "actTakePicture", "params":"[]", "id": "1", "version": "1.0"}
Here is the code used to send the packet. I’ve been attempting to duplicate the second packet, so it doesn’t quite match the first packet’s structure
byte server[] = { 10, 0, 0, 1 };
if (client.connect(server, 10000))
{
Serial.println("Connected");
String request = "{\"method\": \"actTakePicture\", \"params\":\"[]\", \"id\": \"1\", \"version\": \"1.0\"}";
client.println("POST /sony/camera HTTP/1.1");
client.println("Host: 10.0.0.1:10000");
client.println("Connection: keep-alive");
client.print("Content-Length:");
client.println(request.length());
client.println("Accept:*/*");
client.println("Content-Type: application/json-rpc");
client.println("Accept-Encoding: gzip, deflate");
client.println("Accept-Language: en-US,en;q=0.8");
client.println("{\"method\": \"actTakePicture\", \"params\":\"[]\", \"id\": \"1\", \"version\": \"1.0\"}");
client.println();
// client.flush();
// client.stop();
Spark.process();
Serial.println("Packet Sent");
delay(500);
}
I can’t see any error message packets, as only one host can connect to the camera at a time, and I haven’t figured out how to either view received packets on the Core or insert Wireshark into the mix somehow. Can anyone tell me why the first one works and the second one does not? When I captured these via Wireshark by looking at the packets sent via a regular network, Wireshark recognized the first as an HTTP POST packet, while leaving the last one as a TCP packet. I’m not why that is though.