I have some ds1820 hooked up to the computer (Ubuntu) and use OWFS. The temperature readings are found in a file. I have an account on http://emoncms.org/ . The plan is to pass the temperature by http api to emoncms. I'm trying to do this with a bash script. I can get the temperature into an variable but my problem is when to insert the variable into the url string with the CURL command.
If i use the post api example from my browser it will insert new data i.e http://emoncms.org/api/post?apikey=MYAPI&json={power:252.4,temperature:15.4} it works.
When I test it from the cli in ubuntu with:
curl http://emoncms.org/api/post?apikey=MYAPI&json={power:252.4,temperature:15.4} Don't work
curl "http://emoncms.org/api/post?apikey=MYAPI&json={power:252.4,temperature:15.4}" Work (url in quotes)
Basically I need my variable instead of 15.4 in the example above. I think that the it could be the quotes that is the problem. I have tried several ways but no success.
the temperature is an variable called INNE (INNE = indoors in swedish)
Below is how I thought I could get it to work:
curl "http://emoncms.org/api/post?apikey=MYAPI&json={power:252.4,temperature:$INNE}"
Is there any one who can help me with this?
Thanks
/Pär
Re: Passing data to emoncms with CURL (BASH script)
I'm pretty sure that you can concatenate in bash using a full stop
so try
curl "http://emoncms.org/api/post?apikey=MYAPI&json={power:252.4,temperature:".$INNE."}"
Re: Passing data to emoncms with CURL (BASH script)
Thanks, I will give it a try tonight after work.
/Pär
Re: Passing data to emoncms with CURL (BASH script)
Yep, this is possible.
I do the same with my owfs sensors and publish the data to mysql:
Here's an example that merges owfsPath in to the command, and stores the output to the temp0 variable:
owfsPath='/mnt/1wire/'
temp0=$(cat /$owfsPath/28.5F555B010000/temperature | sed -r 's/[[:space:]]+//g')
You can enclose variable names in { } if you need to concatenate them - eg:
$owfsPath becomes ${owfsPath}
Hope this helps.
Mark
Re: Passing data to emoncms with CURL (BASH script)
I finally got it working. combination of the tips above, thanks!
#!/bin/bash
temp0=$(cat /mnt/1wire/28.4864B2000000/temperature | sed -r 's/[[:space:]]+//g')
curl "http://emoncms.org/api/post?apikey=MYAPI&json={inomhus0:$temp0}"
Not really sure what all does but it works after trial and error. Now I need to set up some cron jobs!