Saturday, November 29, 2014

Porting Arduino libraries and pointers

I need to blow off a little steam. What is it with the Arduino library authors and pointers? It's driving me nuts! I just found another author using pointers in really odd places. It was something like this: *((uint32_t *) varName), which basically translates into the unsigned 32 bit int contents of varName and is perfectly legal if varName is a uint32_t pointer (it is not). For some odd reason this works with the Arduino Uno but not with my Chipkit Uno32. I've seen this in parts of the Ethernet library and I think that folks are taking advantage of side effects to get the values they want. Unfortunately I'm not an expert at C++ so I might be wrong.
Anyways, I've fixed the EthernetServer and DHCP library and the ChipKit Uno32 is now getting its IP address from my DHCP server (yea). Now I'll move onto the next issue which is the EthernetClient library. I think I'll start by looking for pointers and see where that leads.
PS: Found another pointer mess and I fixed that one too. I now have the EthernetClient (with DHCP) working. Now I need to get this up onto Git Hub and then add in the MQTT library.

Monday, November 24, 2014

Uno32 serving web pages

I'm rather pleased with myself, probably more than I should be - "pride cometh before a fall" and all. Especially when I really didn't write the original code (I'll give credit to the original code author(s) on the git page). I did make some effort to port it and now I'm going to make an additional effort to correct what doesn't already work. I used it mainly because I couldn't find running code (what can I say, I'm lazy and as a programmer, well, that's a good thing ;-) ). So far, I see that the static IP address is working fine. I haven't tried the DNS functionality, I see the DHCP requests with Wireshark and the DHCP info but the Uno32 never returns from the call. The server is working fine and as you can see below, the Uno32 responds to the HTTP request. I did try the Ethernet client also and it never connected. Still, some working code is a great morale booster.

njc@Mozart:~$ telnet 192.168.1.4 80
Trying 192.168.1.4...
Connected to 192.168.21.4.
Escape character is '^]'.

HTTP/1.1 200 OK
Content-Type: text/html
Connection: close
Refresh: 5

<!DOCTYPE HTML>
<html><body>
analog input 0 is 735<br/>
analog input 1 is 772<br/>
analog input 2 is 768<br/>
analog input 3 is 766<br/>
analog input 4 is 791<br/>
analog input 5 is 794<br/>
Humidity: 44.10 % Temperature: 25.50 *C 77.90 *F
Heat index: 78.88 *F</br></body></html>
Connection closed by foreign host.
njc@Mozart:~$

What I'll work on next is the DHCP part of the code. I think this will the next important step, then the DNS and then the Ethernet client. After that I hope to port over an Arduino MQTT client. I need both the publish and subscribe parts of MQTT. My thinking is that the publish part will publish device updates at regular intervals. The Humidity and temperature in the case of the DHT22. Then the Subscribe part will allow for configuration, such that I can rename a light switch, configure the update times and other details of a device's operations. I think this will go a long way toward making easy to install, HA ready, devices in the home. The end user can then know a lot less about the devices and only need to configure a minimum number of parameters to make device operational. More on that to come as it does require a great deal of thought. At the moment I'm not sure how the HA software will deal with these publish/subscription issues. As I said, more thought is needed.

Saturday, November 22, 2014

ChipKit Uno32 with the WIZnet WIZ550io and some other ramblings

Yea, I finally have basic network code working with the ChipKit Uno32 and the WIZnet WIZ550io board. Yes I can ping and connect to its port 80 just fine. I had various problems with porting the code from the Arduino to the MPIDE environment but I've finally done it. I'm not exactly sure how fast the WIZ550io board is being clock at, I'll need to figure that out. Later I'll make some effort to move it from the SPI to the DSPI library but for now it's working. I'll try some of the more complex examples later. I'd like to use this setup to monitor the temperature and humidity in various parts of the house. My wife has been asking for this to replace the failing display she has on the table next to her. In addition I'd like to add support for MQTT. That way multiple HA systems can subscribe to the information. And, yes, I do have more than 1 HA system running. The Uno32 should have plenty of flash and RAM to handle the job. I'll post the initial code and updates to my Linux HA git account later this week.

I received the initial WIZ550io board from a WIZnet Circuit Cellar contest where I was going to build some HA nodes. While I probably wouldn't have won I'm still going to build the nodes. I had everything planned out except for my employer's work load. I managed to get a last minute work to build automation framework for our testing. I'm actually quite proud of that code. I'm now spending some time to document my framework and I have a number of ideas for improvements and tools to help with the automation. Anyways, back to Circuit Cellar; I might try to write an article for Circuit Cellar once I get this working (and I finish my presenations for TCF and VCF). I'm happy to see that Steve Ciarcia has bought Circuit Cellar. I didn't like the way Elector went out of it's way to hide any article of interest behind an Elector pay wall.

Back on the subject of HA, I've been reading a lot of articles on HA and IoT. I really need to spend some time adding it to my site. There are lots of projects people are undertaking. One of them is OpenHAB and it seems the Java folks have taken some interest in it. I read an interesting article on Java (from Java Magazine) on IoT and HA. The one asumption I found difficult to understand was that the HA node/device had enough resources to deal with the java VM. I don't see that happening with things like the Arduino. But is my assumption or theirs unrealistic? With small devices such as the Arduino we have to put up with a lack of security. The Uno32 has more resources it may be inadequate also. Perhaps we shouldn't settle for small devices with such short comings. Security isn't something you can easily bolt on a later date but we seem to be pushing forward building on that very premise.

Sunday, November 09, 2014

MQTT and Home Automation

I have a couple of presentations I'm working on, one for TCF (HA), the other MARCH's VCF X (Vintage computers and modern microcontrollers). Also, at work I'm extremely busy automating our testing with Perl, DBI and Netcool. I'm learning that Sybase can be a bit painful but I have learned to deal with it (mostly). Additionally I'm busy learning about Big Data and Hadoop (cool!). Lots of learning, coding and testing. Oddly enough I enjoy this.

Now on to HA, I've be poking around trying to figure out what I want to do with my home automation. I'm currently using Misterhouse (MH) and I want to continue with that but I want to also work on the MH's floorplan software. The code changes I want require that object updates be seen in realtime. This where, I hope, that MQTT comes in. Updates are easy, publish and subscribe. I'm not sure how I'll get MH to publish its updates yet. I'm also not sure how to take care of the object's actions yet but I am working on that. In the meantime I think I might be able to take advantage MQTT to allow my outside devices (Vera) to share information with Misterhouse. I'm hoping I can use it with other HA systems (like the ISY99 or the TCP by Connect). I've also found a nice MQTT client for the Arduino. I'm currently working on an Arduino with Ethernet, temperature and humidity sensors. At the moment, it seems like a good idea but I've investigated other ideas only to find that they add complexity. So, let's see where this takes us.