Online heating system control project

From Wiki2

back to electronics

online heating system control project

=homecontrol jquery-mobile app]]

system versions -arduino+server code

version B - no more String class, missing readings retain order

Next: only record to db if temp changes

in c://Users/tim/Documents/tech/electronics/Arduino/hsc_run.ino
in c://Users/tim/Documents/tech/electronics/Arduino/hsc_setup.ino
in c://Users/tim/Documents/tech/electronics/Arduino/hsc_readSetup.ino
version A - mega as server sending to ReSt API and client receiving new setpts

in c://Users/tim/Documents/tech/electronics/Arduino/thermoc.ino

bits and pieces

version 6

Moving things to 10.0.1.101 but first set up api framework there
Added rewrite rules in /etc/apache2/sites-available/default by following beginner link <syntaxhighlight> <Directory /var/www/hsc> RewriteEngine On RewriteRule feed/([0-9]+) /var/www/hsc/index.php?id=$1 RewriteRule feeds /var/www/hsc/index.php RewriteRule datastreams /var/www/hsc/index.php?id=$1 RewriteRule prog /var/www/hsc/index.php?id=$1 RewriteRule progs /var/www/hsc/index.php?id=$1 </Directory> </syntaxhighlight> Test code to parse url <syntaxhighlight> <?php echo("hi dog
"); print_r($_SERVER['REQUEST_URI']); echo "
"; $urlarr = (parse_url($_SERVER['REQUEST_URI'])); echo "
"; print_r($_GET); echo "
"; print_r($urlarr); echo "
"; $pathstr=($urlarr["path"]); echo $pathstr; echo "
"; print_r(explode("/", $pathstr)); ?> </syntaxhighlight>

version 3
php www-data program that creates a crontab and calls a C program that executes root commands to copy it into crontabs and install it
write a php file that PUTS some light on on the AVR
collect data from AVR and store it in mysql
view the saved data on a client using javascript

code working on arduino

versions now use both arduino and php code so new versions sill be listed under #system versions -arduino+server code
version 5
raw DS18B20 to server, convert and send back to serial monitor

Uploaded to Arduino is hsc_tempJSONphp.ino Raw data is sent by arduino to /var/www/feeds/getnoise.php which puts it in an object and then creates another object containing F converted sensor readings for data coming off ONEWIRE connected sensors. Then it sends that data back.

Trying to convert to float on the Arduino wasn't working. Why push it? I've got unlimited power on LAMP server.

version 4 - temp readings beyond serial monitor
version 4a - DS18B20 readings to JSON
version 4b - JSON from arduino to PHP server
a) separate out a function to provide a reading to send to cosm for pin 0(14) and 1(15)
1 one possibility - send to cosm. This is better than having a webclient like thermometer.ino. Get it to Cosm and then later set up an api like cosm
version 3 - onewire demo

Put sample code in function getTemp(). Subsequent calls of the function don't reset the device counter. this is good.

DS18B20wiring.PNG

On serial monitor running DS18x20_Temperature.ino ala the library here. Of note: How it polls each device: <syntaxhighlight>

 if ( !ds.search(addr)) {//this is where it loops to the next address
   Serial.println("No more addresses.");
   Serial.println();
   ds.reset_search();//if there are no more devices go back to start of list
   delay(250);
   return;
 }

</syntaxhighlight>

version 2
Online thermometer creating web page in which you call for the data by clicking a button. Uses design from Practical Arduino in /tim/Documents/electronics/arduino/thermometerthermometer.ino and it runs at http://10.0.1.79
version 1
Take random readings from analog pins start an etehrnet client that sends them out to http://cosm.com (mcktimo 6j) every ten seconds :comtest.ino

final narrative

An Avr takes in temperature readings from multiple locations. At the control room the AVR hub polls temperature and for each zone knows the set temperature, the default temperature and whether or not a zone is ON and how long it has been on. If it doesn't hear from the (linux) scheduler then it falls back to act as a multi-zone thermostat set at the default temperatures. Through a rudimentary display it would allow you to set temperatures for each zone.

The scheduler would take temperature data from the AVR client and would know the schedule. Whenever a schedule change point would come up, it would notify the AVR and instruct it to change the set point. It would do this via chrontab maybe.

The controller would on the client probably an HTML5/javascript client. Here you can read the temperatures and view the schedule. You can override or change the schedule.

possible routes

A cheap circuit like http://www.craig.copperleife.com/tech/thermo/ or more complicated http://www.rentron.com/project01.htm using http://datasheets.maximintegrated.com/en/ds/DS1620.pdf which can be overridden by server program that controls multiple thermostats.

ReST

Angular and PHP

Apache setup
Add rewrite rules

so a restful path /hsc/feeds/1234 (which doesn't really exist) sends you to the API which processes the request using the /feeds/12345 information from the path.

In /etc/apache2/sites-available/default add rules like <syntaxhighlight lang="html5"> <Directory /var/www/hsc> RewriteEngine On RewriteRule feed/([0-9]+) /var/www/hsc/index.php?id=$1 RewriteRule feeds /var/www/hsc/index.php RewriteRule datastreams /var/www/hsc/index.php?id=$1 RewriteRule prog /var/www/hsc/index.php?id=$1 RewriteRule progs /var/www/hsc/index.php?id=$1 </Directory> remember to restart apache /usr/sbin/apache2ctl restart </syntaxhighlight> The API processing code resides in /hsc in this case.

when to GET PUT POST
GET when you want some data
PUT when you've got data to put in the API
POST when you want to setup something new
DELETE duh

In the case of home_system_control (hsc):


  • GET request to /api/users – List all users
  • GET request to /api/users/1 – List info for user with ID of 1
  • POST request to /api/users – Create a new user
  • PUT request to /api/users/1 – Update user with ID of 1
  • DELETE request to /api/users/1 – Delete user with ID of 1
refs
cosm curl helper
http://api.cosm.com/v2/feeds/83080/datastreams/noise.csv?start=2013-01-11T19:30:00Z&end=2013-01-11T21:00:00Z&interval=0 doesn't work
http://cosm.github.com/cosm-js/tutorial/
accessing-incoming-put-data-from-php
create-a-rest-api-with-php
http://rest.elkstein.org/2008/02/using-rest-in-php.html
http://blog.garethj.com/2009/02/17/building-a-restful-web-application-with-php/
get for my feed
making-reliable-connections-with-arduino

Cron Jobs

Hudsonvalley#cron_and_backups
http://net.tutsplus.com/tutorials/php/managing-cron-jobs-with-php-2/
http://stackoverflow.com/questions/4421020/use-php-to-create-edit-and-delete-crontab-jobs

parts

DS1620 Digital Thermometer and Thermostat

In a thermostat circuit $2.20 for dip

DS18B20 Maxim 1-wire temperature sensors
DS18B20 datasheet$1.00 each for chip, $3.00 each for waterproof sensor
one-wire protocol
https://arduino-info.wikispaces.com/Brick-Temperature-DS18B20 multiple
OneWire tutorial another better library
color code for encased DS18B20 sensor red=vcc,black=gnd,yellow=data

DS18B20-pinout.jpg