I have an USB Air Sensor for the Raspberry Pi and I want to send it’s values to my Ubidots account. The program to get the airquality is called “airsensor”:
./airsensor -v
450
453
457
460
453
How can I send these continuous (~ every 15 seconds) output values to Ubidots?
I already tried piping it with curl, but without success.
./airsensor -v | curl -X POST --data-urlencode value@- https://things.ubidots.com/api/v1.6/variables/[VARIABLE-ID]/values/?token=[TOKEN-ID]
About your question using the pipe utility of Linux, I would advise you to use a concatenated command instead of trying to pipe your result, below you can see some examples:
Hi there, as you are using bash commands that returns a value in a infinite loop with a fixed time difference you should capture that result using the ‘read’ command in an infinite loop, I believe that something like the snippet below should work properly for your case:
./airsensor -v | while read line; do curl -X POST -d "value=$line" "http://things.ubidots.com/api/v1.6/variables/[VAR-ID]/values?token=[TOKEN]" ; done
I am at best confused and at worst dazed. I have tried to POST data to my ubidots device using curl without any success. I just get, to me, un-helpful replies.
with my device, variable labels and API-Token in place of the placeholders, and in response I received:
curl: (3) [globbing] unmatched close brace/bracket in column 10
curl: (3) [globbing] unmatched close brace/bracket in column 21
{“detail”: “Authentication credentials were not provided”}
So I figured out how to get rid of the “globbing” error by using -g or escaping the double quotes in the JSON and enclosing the -d data with double quotes. But why does the last one give me the “This field is required” message? And why did the previous attempt give me the “Authentication credentials were not provided” message but the last didn’t when I used the same credentials for both. And finally, how can I actually send a POST using curl? I assume I am doing something incorrectly but what that is, is not apparent to me.
Hi there @larrycook99 , you have to make available the server’s answer to make additional debug, if you use curl put “-vvv” at the end of your curl command to get all the feedback from the server.