How can I test the process of sending data to Golioth when something isn't working?

I’ve encountered this issue a few times: my device is connected to Golioth, but when I send data to Golioth it’s not arriving as expected. I will share a few troubleshooting tips, with the best one last (try using the coap tool).

  1. Make sure the JSON you are sending is valid. I like to use the one on Duck Duck Go search engine by searching for “json validator
  2. Check that your string buffer is long enough. I’m often using snprintk() to fill a buffer before sending it to Golioth and if you run out of space, you’ll be missing the end of the JSON and the server will ignore the message.
  3. Use the Golioth coap tool to test sending the data

Golioth has a fantastic command line tool called coap that looks exactly like an embedded device to the server, it can even use the same credentials. Testing with this tool will retrieve additional error messages not available to the embedded devices.

Instructions for installing the coap and goliothctl command line tools are available in our quickstart.

coap --path /.s -m POST --host coap.golioth.io --psk-id my-board@my-project --psk strong_password -b myquery.json

Above I’ve used coap to send a test JSON to LightDB stream

  • The path is using /.s to send stream data, you can send state data using /.d
    `* Get your device PSK-ID and PSK from the Golioth web console
  • Because we are issuing this from the command line, I needed to “escape” the quotes in the JSON payload by prefixing them with a backslash (). It’s possible to place your JSON in a file and send that instead, without the need to escape characters.
coap --path /.s -m POST --host coap.golioth.io --psk-id my-board@my-project --psk strong_password -b "{\"test":\"case\"}"
1 Like