Home Automation / Temperature Sensors Part 2

Posted on January 29, 2015

0


With the checksum working, I moved on to the next stage: getting the temperatures out of the Arduino. I found an example webserver that served up the analog inputs using a Ethernet shield compatible with mine. A quick test and a little network configuration to get a static IP address and it ran. Now comes combining the 2 “sketches”.
I quickly learned that you can have multiple files in a project in the Arduino IDE. Supposedly you can name the remaining files as C files (which would make my Subversion repository happy because it doesn’t realize my ino sketch files are just C files). Reading about multiple files filled in some gaps in my knowledge. I had wondered why you don’t need to forward declare subroutines and variables. It seems the Arduino IDE has a pre compile stage where it creates these for you. But if you include additional C files in your project, you have to revert to doing so yourself.
I also found a Arduino function called “yield” that allows for cooperative multitasking. This is great because I didn’t want to rewrite my 2 existing sketches, each of which is an endless loop. I could simply sprinkle in yield calls in the main loop of each as well as anywhere within the code that went into tight loops without sleeping (the new yield functionality apparently also rewrites sleep to be a cooperative yield). It turns out this is only in the new beta. So I reinstalled using the beta. This didn’t help since it turns out yield is only supported on the new 32-bit processors. I’m not dropping $40 bucks to get one when the $10 8-bit processor is fine.
So I found a 3rd party library that offers a simple cooperate library called SCoopME. You have to declare the tasks, but no biggie. So I set up the main sketch to declare the tasks and call the main loops of the webserver and temperature C files. For some reason, the compiler uses different flags when you use the Arduino IDE to invoke it vs. invoking it on ino files. So C99 syntax was not allowed. I manually added this flag in the Arduino config files, but still had some issues with including libraries that I threw my hands up on. I found by naming the additional files with ino extensions, everything worked. I did run into an issue where running the webserver under one of the extra tasks prevented everything from working. Invoking it from the native “loop” instead resolved that. A little problem to look into later, especially if I ever want to use more than 2 tasks.
Now I am running the 2 sketches simultaneously. Serving up a web page while reading RF temperature sensors (dumping the sensor readings to the serial port for debug for the moment). It was then quick work to redesign the webserver’s minimal page to display the temperature sensors. Now I have a webpage that shows the temperatures. Woot!
A little reading today showed how to create overlays onto pics in a HTML page, so the path forward for creating a map or blueprint of my house with temperature values for each room showing in that room looks straightforward. My next step is to go to my server and create a static page doing so to work out the details. Then write some PHP to read an XML description of which sensor value goes where on the page, and a wget to the Arduino and we should be there. Stand by for Part 3!

Advertisements