I am a newbie. Last week I couldn’t spell API but after much reading and searching I have made real progress. But today I have to admit I am stuck. I hope this forum - and this category - is appropriate for my question.
The good news: I am able to control my fireplace (on/off, flame size, fan speed) using the Bond API commands. I can execute the HTTP code successfully using either a windows cmd line interface (with curl), or by importing the raw command into Postman. So I am confident I have the right Bond API syntax and logic.
The bad news: My objective is to use an ESP8266 (Arduino) with additional logic to control my fireplace. That’s where I am stuck. I have reviewed a lot of code - but I can’t find examples of an ESP8266 interfacing with a Bond. So I modified a simple example that does an HTTP PUT call and tried to substitute my BOND API commands. Unfortunately I keep getting json errors.
I concede that this is more of a coding issue of an API call within an ESP8266, as opposed to a BOND API issue (especially since I know that my commands work in Postman). Nonetheless, after struggling for some time, I hope someone on this forum might be able to help me over this hurdle.
Here is one of my commands that works successfully in Postman:
curl -X PUT -H “Content-Type: application/json” -H "BOND-Token: fd****1" -i http://192.168.../v2/devices/7d/actions/TurnFpFanOff -d “{}”
Following is the esp8266 code that I have modified to use the above command. It returns a json parse error {"_error_id":23,"_error_msg":“json parse error”}
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
void setup()
{
Serial.begin(115200); //Serial connection
WiFi.begin(“my sid”, “my password”); //WiFi connection
while (WiFi.status() != WL_CONNECTED)
{ //Wait for the WiFI connection completion
delay(500);
Serial.println(“Waiting for connection”);
}
HTTPClient http; //Declare object of class HTTPClient
http.begin(“http://192.168../v2/devices/7d/actions/TurnFpFanOff -d “{}”");
http.addHeader(“Content-Type”, “application/json”); //Specify content-type header
http.addHeader(“BOND-Token”, "fd*******1”);
int httpCode = http.PUT(“Message from ESP8266”); //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
}
void loop()
{
}
Thank you very much for your assistance.