Showing posts with label 1-Wire. Show all posts
Showing posts with label 1-Wire. Show all posts

Tuesday, 23 April 2013

Temperature monitoring system V0.2

Here is version 0.2 of my Arduino project of Temperature Monitoring System.
It is based on a JY-MCU basic AVR board with ENC28J60 Ethernet interface and a 1-wire bus to provide a local web server with real time temperature readings of any number of 1-Wire thermometers. In addition, it can be configured to post the readings to COSM data feed.

This is running at my house for quite some time and is posting indoors and outdoors readings every 10 min to the following COSM feed: https://cosm.com/feeds/100389


The hardware description can be found in my other post.
To compile the project download the JY-MCU hardware profile for Arduino and the following libraries:

  1. EtherCard
  2. EEPROMex
  3. OneWire
  4. DallasTemperature
The code can be download from here: TempServer V0.2.ino

The server use DHCP to configure the TCP/IP stack and then start (led 7 remains on while setting up, then led 8 start to blink for normal operation).
The configuration link on the main page will bring up the COSM configuration page where you can configure the posting interval, the feed id and the COSM API key (to reset this configuration, hold switch 1 when the program starts).

In the next versions I am planning to enhance the following (not in a particular order):
  1. Enable to name each sensor for display in the list and for posting the date to COSM.
  2. Log up to 96 past readings in the device EEPROM (every 15 min for 24 hours).
  3. Show the min/max of the logged values.
  4. Show graph of the logged values.
  5. Use network time to make sure date logging and posting is done properly even when the device restarts frequently (currently, the posting of data is done after the device is constantly on for the selected posting time, that is, if the post of data is every 10 min, and the device restart every 7 min for some reason, no data will ever be posted).
  6. Improve the posting code to retry on HTTP errors (currently the code ignore the returned HTTP code and does not check for time out).
The main challenge to accomplish items 1 and 2 is the limitation of the EEPROM size (1KB), but with limiting the name to 15 characters and 10 bit per reading, I can support up to 10 devices on the bus.

Please let me know your thoughts (especially if you willing to give it go).

Thursday, 24 January 2013

A basic temperature web server

With the help of jQuery Mobile , 1-Wire libraries and yet, another Ethernet library - EtherCard, a proper page is up and running.


Only 2 sensors at the moment, one inside and one outside as you can imagine.
Although the 1-Wire bus and the software can have many more, the other sensors I have across the house are too far from the router and I need to get a wire across.
The 1-Wire hardware is very simple: the bus is connected to an I/O pin with a pull-up resistor to VCC, the strong pull-up to allow temperature conversion with parasite power is achieved by setting the pin to output high by software to get more current into the bus.
The code use the DallasTemperature library by Miles Burton, which use the OneWire library to manage the bus itself.

The main challenge is to fit the code and the web content (html, css, js) on the small program memory the processor have (30KB), and to make sure each response does not exceed the TCP/IP buffer size I have allocated (1KB).
jQuery CDN to my rescue!
This has 2 advantages: a) I don't need to store the jQuery on the processor. b) the files are probably already got into my device cache when I browsed other mobile sites.

The HTML:

<!DOCTYPE html>
<html>
<head>
  <meta name='viewport' content='width=device-width, initial-scale=1' />
  <title>TempServer</title>
  <link rel='stylesheet' href='//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css' />
  <link rel='stylesheet' href='main.css' />
  <script src='//code.jquery.com/jquery-1.8.2.min.js'></script>
  <script src='//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js'></script>
  <script src='//stevenlevithan.com/assets/misc/date.format.js'></script>
  <script src='main.js'></script>
</head>
<body>
  <div id='main' data-role='page'>
    <div data-role='header' data-position='fixed'>
      <h3>Is it hot?</h3>
    </div>
    <div data-role='content'>
      <ul id='list' data-role='listview' data-inset='true'></ul>
      <p id='info'></p>
    </div>
  </div>
</body>
</html>

The Java Script (not minified):

$(document).ready(function () {
    reload();
});

function reload() {
    $.getJSON('list.json', function (data) {
        var items = [];

        $.each(data.list, function (key, val) {
            items.push('<li id="' + val.id + '"><a><h3>' + val.name +
            '</h3><p>' + val.id + '</p><p class="ui-li-aside">' + 
            val.val.toFixed(1) + ' &deg;C</p></a></li>');
        });

        $('#list').html(items.join('')).
            trigger('create').listview('refresh');

        var time = new Date(data.uptime);
        $('#info').html(
            'Uptime: ' + time.format('isoTime') +
            ' (' + data.free + ' bytes free)');
    });

    setTimeout(reload, 10000);
}

The CSS:

.ui-li-aside 
{
    font-weight:bold;
    font-size:xx-large;
}
#info
{
    margin-top:10px;
    text-align:center;
    font-size:small;
}

And the JSON response with the measures:

{
"list":[
{"id":"104938A501080057","name":"Sensor 1","val":16.188},
{"id":"28DA3E95040000CD","name":"Sensor 2","val":0.813}],
"uptime":57430902,
"free":620
}

You can get the full sketch in here: TempServer.ino

The hardware schematic is in my other post: The hardware is ready!

Now I want to utilize the 1KB EEPROM on the processor to store some temperature log and a proper name for each sensor, this will have to come with some more HTML pages to display a nice graph and edit the name for each sensor.
I hope I will have the space, the current code consume 17KB out of the 30KB available.

Thanks.