noel1983
Posts: 1
Joined: Fri Jan 02, 2015 9:57 pm

Pushing temperature to a url

Fri Jan 02, 2015 10:03 pm

Hi all,

I've had a pi for a fair while and done nothing with it until yesterday when I got stuck in and now have a usb webcam hooked up to Motion which is working great.

I'm then accessing the lastsnap.jpg from my mac mini which is my home automation server running Indigo.

So....next project is temperature sensing. I have a few one wire temp sensors on their way to me and i've seen a few guides online on how to hook these up.

What i'm looking to do is for the pi to read the temperature every x minutes, ideally every 2 minutes or so, and then to put to a url as follows:

http://192.168.1.28:8176/variables/temp ... t&value=22

where temp_landing is the name or id associated with the specific temperature sensor and 22 is the temperature reading.

This then sets the variable within the home automation software on the mac mini and allows me to take actions based on the temperatures.

I'm an absolute beginner with the pi's, I can ssh, just about find my way around but know next to nothing about scripting etc although I can search google and read guides with the best of them!!

If anyone could offer me any pointers to guides on how to achieve what i'm after this would be a massive help and i'd be very very grateful.

Many thanks

Noel

rgrbic
Posts: 128
Joined: Thu Jun 12, 2014 1:07 pm
Contact: Website

Re: Pushing temperature to a url

Fri Jan 09, 2015 6:15 pm

You can use websockets to send the data to webpage (client). Here is one example how to use websockets to display temperature on a webpage.
At 127.0.0.1
Twitter: @rgrbic
IoT-projects.com

wayner
Posts: 84
Joined: Thu Oct 25, 2012 1:40 am
Location: Toronto, Ontario, Canada

Re: Pushing temperature to a url

Sat Jan 10, 2015 4:58 am

This web page has lots of good info that should help. You should be able to do what you want by modifying the Python script to compose the URL that you want.

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: Pushing temperature to a url

Sat Jan 10, 2015 9:01 am

Cgi or wsgi with post is what you're after. Google away.
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Pushing temperature to a url

Sat Jan 10, 2015 4:21 pm

The way I would approach this problem is like this:

Write a program that will read the temp from the sensor and write it to a file appending the latest reading to the file.
something like:
while true
do
sleep 120
TEMP=`[read the temp sensor]`
DATE=`date`
echo "$DATE $TEMP" >> /var/log/mytemp-data
done

Then I would have a cgi script that simply tailed the file. Something like:
tail -1 /var/log/mytemp-data

All done

To clean up the file periodically, simply copy /dev/null to the file. There are other ways to clear a file too.
> /var/log/myfile
is another way
If you want to save the old data then logrotate() comes to mind.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

wayner
Posts: 84
Joined: Thu Oct 25, 2012 1:40 am
Location: Toronto, Ontario, Canada

Re: Pushing temperature to a url

Sat Jan 10, 2015 4:27 pm

My link didn't work in the above post, but the following article logs temperature every 15 minutes using a cron job and logs it to a SQLite database. The next article in this blog series shows how to build nice charts using a call to the Google Charts API. IMHO a database is a more elegant way to do this than a text file. Before this I had never done logging to a database but it is actually quite simple - both to store the data and to access it.

http://raspberrywebserver.com/cgiscript ... ogger.html

evilkitty
Posts: 370
Joined: Tue Apr 15, 2014 11:39 pm

Re: Pushing temperature to a url

Sat Jan 10, 2015 7:34 pm

why not just write a few lines in php?

Code: Select all

<?php
if(isset($_GET['id'])){
$id=str_replace('/','',$_GET['id']);// (str_replace is for security reasons, prevent attacker from getting data from any file on system that www-data has read access to);
if(!file_exists("/sys/bus/w1/devices/$id")){
die("that ID is not valid");
}
$data=file_get_contents("/sys/bus/w1/devices/$id/w1_slave");
$data=explode(" ",$data);
$data=substr($data[count($data)-1],2);
echo intval($data)/1000;
}
else{
echo "yea, if you would give me a id, that be great";
}
?>
My Pi Server: http://imgur.com/a/6xIUI | Thermostat: http://imgur.com/a/4LVnT

Return to “Automation, sensing and robotics”