Hello,
I am trying, and failing, to communicate from an Arduino sketch (ARD) to a custom Device Handler (DH) on a LAN-connected SmartThings Hub (V2). Specifically, the response is HTTP 202 Accepted, with no other visible side-effect. The events list on the Hub does not show this call. Similarly, the events list on the device does not show this call. My goal is to get the payload in the “parse()” method of the device handler. Following are all the troubleshooting steps I’ve already tried. I would appreciate any suggestions about what might be going wrong, or at least how to further troubleshoot the issue.
- The Arduino board and the Hub are on the same network. The Arduino board is on the WiFi network, the Hub is connected directly via Ethernet to the same Wifi router.
- In the opposite direction, the DH can talk over HTTP to the ARD, seen as a custom device (using new physicalgraph.device.HubAction(…))
- The DH sends the “callback” URL and PORT, via an HTTP GET, to the ARD. I confirmed the values are properly received on the ARD side.
- The ARD is able to make GET requests over WiFi and fetch data (e.g. the google.com homepage)
- The ARD is able to properly connect to the URL and PORT sent by the DH, and can send a payload (see code below). It gets a 202 response. If I try other URLs or PORTs, I get a connection error.
- If I use Fiddler on my laptop to make a POST request to the same IP/PORT, I at least see the corresponding event (with the correct base64-encoded payload) in the Hub’s list of events. Why it’s not in the DH’s event list (i.e. why it doesn’t get routed to the DH, and, eventually, to the DH’s “parse()” method) is a whole different question. I’m trying to take things one at a time…
- The ARD code that I’m using is as follows, based on HTTPClient from ESP8266HTTPClient.h:
HTTPClient httpClient;
if (httpClient.begin(IP_FOR_ST, atoi(PORT_FOR_ST), “/”))
{
String testString = String(“{"status":"test"}”);
httpClient.addHeader(“Content-Type”, “text”);
httpClient.addHeader(“Content-Length”, String(testString.length()));
int httpCode = httpClient.POST(testString);
String response = httpClient.getString();
httpClient.end();char message_text[600]; itoa(httpCode, message_text, 10); DEBUG(LOG_NO_FILTER, message_text); DEBUG(LOG_NO_FILTER,payload.c_str()); DEBUG(LOG_NO_FILTER, "---StatusToST: SUCCESS---");
}
- The ARD code that tests a GET on google.com is included below. It gets back an HTTP 301 with a full HTML body:
HTTPClient httpClient;
if (httpClient.begin(“172.217.14.228” /Google/, 80, “/”))
{
httpClient.GET();
DEBUG(LOG_NO_FILTER, httpClient.getString().c_str());
}
As I mentioned above, any ideas, questions, or suggestions are welcome. Thanks!
Cheers,
~alex