Webhook publishing to MySQL via php


#1

I’m porting code from Adafruit Feather FONA where I post data to a php file to push data to a MySQL database, and struggling to get the webhook to work properly - or post any data at all. Data shows up in the web console fine.

Here is the url that should post data:
http://xx.xx.xx.xx/Hologram_Script.php/?Time=2017-08-15 07:11:16&DeviceID=1357ABCD&Status=1&SigStrength=17

Here is the code that sends data to the Hologram Cloud:
HologramCloud.print(“Time=”);
HologramCloud.println(Clock.currentDateTime());
HologramCloud.print("DeviceID= ");
HologramCloud.println(simCCIDReply);
HologramCloud.print(“Status=”);
HologramCloud.println(Status);
HologramCloud.print(“SigStrength=”);
HologramCloud.println(HologramCloud.getSignalStrength());

This is what I put as the destination URL in the webroot:
http://xx.xx.xx.xx/Hologram_Script.php/?Time=Time&DeviceID=DeviceID&Status=Status&SigStrength=SigStrength
NOTE: Replace the ** with <<
and >>
The HTML editor hides the content inside of those characters.

Payload: NONE

The error I get on the console is: Error decoding JSON for variable ‘Time’

Any help greatly appreciated!


#2

Hi,
Right now our cloud can do this, but you have to send it JSON from the Dash so it knows how to parse each field. I’d recommend using the Arduino JSON library to do this.
You can use this in the Arduino IDE by going Sketch->Include Library->Manage Libraries and then find ArduinoJson in the list and install it.

Stick #include <ArduinoJson.h> at the top of your sketch

Then, you can do something like this:

  StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;
  char msg[128];
  JsonObject& root = jsonBuffer.createObject();
  
  root["time"] = Clock.currentDateTime();
  root["signalStrength"] = HologramCloud.getSignalStrength();
  root.printTo(msg, sizeof(msg));
  HologramCloud.sendMessage(msg);

Then in your route, you can use variables like <<decdata.time>> or <<decdata.signalStrength>> and it will pull those fields out of the JSON and put them into the payload.


#3

P.S. You’ll also need to define BUFFER_SIZE for the JSON library

I have it set like this:

const int BUFFER_SIZE = JSON_OBJECT_SIZE(5);

More information is at https://bblanchon.github.io/ArduinoJson/assistant/index.html