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.