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).

25 comments:

  1. Thank you for sharing.
    But I could not find the library here https://github.com/jcw/ethercard (unable to connect)
    Can you upload ethernet library to else where?
    Thank you.

    ReplyDelete
    Replies
    1. You can find a copy of the library in https://sites.google.com/site/hagaishatz/arduino
      I will appreciate if you can share your thought on the solution.
      Regards.

      Delete
  2. Great project! I am wondering if you can help me get this working on Arduino with ATmega 328p chip? I'm using a ENC28J60 shield (uses pins 10 - 13, and 2).

    I refreshed the 4 libraries you use with the same version to be sure I am using the same code. I also update the line:
    if (ether.begin(sizeof Ethernet::buffer, mymac, 12) == 0)
    to:
    if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
    as the "arduino shield" version of the ENC28J60 uses pin 10 for CS.

    Sketch compiles and uploads fine, I get a DHCP address, and display the web page. It shows the "is it hot?" header at the top of the page, but no other content. I used serial debugging in your sketch, adding Serial.print(tempC); so I could see if it is reading my oneWire bus, and it is, I see the output from my DS18S20's each time the webpage calls. I also see in my browser (ctrl+shift+i) the reload calls.

    I cant seem to figure out why it is not rendering the temps in the browser page. I tried your older version of this project (The one without EEPROM) with the same results, so I thought I'd try your new version, and am seeing the same problem. Any troubleshooting you have would be greatly appreciated!!

    -Joe

    ReplyDelete
    Replies
    1. Thanks for trying this out.

      If the reload calls you inspect in the browser tools are with a proper response content then the problem is probably in the javascript code.
      Are there any javascript errors in the browser console?

      -Hagai

      Delete
    2. Thanks for getting back to me. I am very very new to JavaScript, so I suspect you are right that there are potentially errors in my code. I am working through that code over the next week or so, and I will post my findings.

      thanks!
      Joe

      Delete
    3. I too have the same problem.

      The browser console says this:

      event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

      Delete
    4. No way to edit :-(

      I cant seem to find the event.returnValue in the js code, or any where in the schetc. Hagai can you help with this?

      Also I see that your temp server is down, or at least not posting to Xively. Cant seem to get that to work either, but I think the tow eerors hang together

      Delete
    5. This comment has been removed by the author.

      Delete
    6. Kryten, Joe,
      As Kryten noticed, my device is not running since I moved to my new house. It looks like some compatibility problem with jQuery, my JavaScript and the browser that you are using. I will try to have a look on this over the weekend.
      Cheers, Hagai.

      Delete
    7. Thanks for that Hagai.

      Here is the StackOverflow link again since I deleted the last post I did.

      http://stackoverflow.com/questions/20045162/event-returnvalue-is-deprecated-please-use-the-standard-event-preventdefault?answertab=active#tab-top



      Im kinda stupid some times :-p

      Delete
    8. From what I can see, Not that Im any good with java scripting, I think it will be enought to change the jQuery versions.

      Here:
      http://blog.jquery.com/2013/04/18/jquery-2-0-released/

      Althou It might throw off the nice GUI you made.

      There are som enice tips on migrateing to newer versions here :
      https://github.com/jquery/jquery-migrate/#readme


      Looks (to me) like the trick is to change the lines:

      278-281 in the .ino file
      (had to cut all the HTML part of the code in order to post it)

      href='//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css'/>
      "'//code.jquery.com/jquery-1.8.2.min.js'>
      '//code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js'>


      I dont have the time to look into wich versions we should use in order to fix this as Im am @ work.

      Delete
    9. This comment has been removed by the author.

      Delete
    10. So I got home started testing my theory but no luck.

      After checking some more in the Developer tools (in Chrome).

      It looks to me that the Temp is not beeing posted to the list view. The only child I see in the list view is the updatet time.


      I now think that the error is some where in the second and third script line of mainJs function.

      Hope this helps you a little Hagai and I have no clue into Java scripting so I cant help. Sorry about that.

      Also Im not going to be able to check anything until monday as I will be away at a cabin ( where I hope to put this in the end)

      Delete
    11. Thanks for your efforts.
      Can you post a sample of the readings response you get into the browser?
      Have a nice weekend.

      Delete
    12. I tested the javascript using a simulation of the actual Arduino and it works as expected using the current jQuery 1.8.2 and jQueryMobile 1.2.0 versions.
      I suspect that something is not right with the list.json responses returned from the device.
      They should look something like this:

      {"list":[{"id":"AABBCCDD11223344","name":"Sensor 1","val":2.411},{"id":"AABBCCDD11223355","name":"Sensor 2","val":2.866}],"uptime":76391299,"free":545,"feed":""}

      But I don't have the device with me at the moment to test it myself. Will try to find some time over the weekend.

      Delete
    13. I did not see any thing looking like that. ( i might not have looked in all the right plases.)

      Sorry for late reply, have been occupied other ways. I will check as soon as i can, bit that means Monday

      Delete
    14. I have added serial output in order to see if the OW is read at all and it is. (first thing I did when there was no temp showing).

      Delete
    15. Here is teh output from dev console

      {"list":[{"id":"2882ABC50200002E","name":"Sensor 1","val":T},{"id":"2836C7BC020000FE","name":"Sensor 2","val":T}],"free":258,"intr":15,"feed":"163946092","cosm":"216.52.233.120"}

      It looks to like the tempC float value is not being entered in to the string. I can read out the tempC using serial output.

      Delete
    16. Thanks, indeed the temperature float value is not written to the response ("val":T).
      The issue is in the EtherCard.cpp - uncomment the following line at the top of the file:
      //#define FLOATEMIT // uncomment line to enable $T in emit_P for float emitting
      The code use BufferFiller::emit_p to build the response and is unable to write float values unless this is enabled in the library.

      Looking forward for positive news.

      Delete
    17. There you go all perfect!

      Thanks for helping Hagai. I really appreciate it.

      It dos not seem to hang on to the API key for xively. The last 4 characters are being transformed into wild cards as a dimond shape with a question mark inside

      Delete
    18. It looks like it got fixed by itself

      Delete
  3. When I try to compile I get error: 'EEPROM' was not declared in this scope.

    Im on a Arduino nano using mega328 chip.

    ReplyDelete
    Replies
    1. Had an issue with the way I installed the EEPROMEx lib.

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. How are you getting on with adding names to the sensors?

    One Idea is to scan the OW bus during atrstup and storing the adresses in eeprom, setting the names like setting COSM /Xively API key.

    I dont have the skills (yet) to fix the EEPROM stuff to do this but i can have a go to help you out a bit

    ReplyDelete