Wednesday, September 9, 2015

Home Automation Part 5 ESP Code

After a lot of time siting frustrated in front of my computer going why doesn't this work and why does that I finally have code that works. A section of the code is still basically the same as with the Ethernet code I had before but I had to go through all of that and change a bunch of variables and references because of how the new library worked. Currently the ESP is set to DHCP because every time I try to set the ip address to 192.168.x.x it claims to have an address of so I am still going to try to to get a static ip setup but the god news is that the router I am using is DDWRT and I think it gives an ip address out based on the mac address so the ESP gets the same ip address each time. I am also able to set a static ip on the router. For my purposes I do not care what the ip address is for each device, what I care about is the devID I give it. My code is in the link below. Most of it I can explain. Some of the stuff in the callback function I am a bit confused on but it works. You can get the topic that was received to come in as a string but the message is not a string or a char so you need to do some funky things to it.

When I was getting everything buttoned up yesterday I was curious how much current was being drawn so I hooked my voltmeter up in series and everything was working fine. I was still modifiying code at this point and after a little while I kept getting stack errors and the serial port would go nuts with information. Then the ESP would reboot and work fine again for a little and repeat. After searching the internet it turns out that it was a power supply issue. Now my volt meter said I was only using about 0.1 amps so I didn't think it was a current draw issue but after a while I took the volt meter out of the loop and it has run since without any issues.

After getting everything working how I wanted it was time to start moving onto the next step. The enclosure. In the long run I want to make a light switch replacement but I figured start with something simple. I happened to have this nice enclosure box and a few outlets so I am going to make a floor switch with 2 buttons ontop that you can push with your feet. This will make it easy to test while I figure out a good small setup for a light switch replacement.


Tuesday, September 1, 2015

Home Automation Part 4 Mosquito v1.4 and ESP start

Now that I have some free time again it is back to work on my home automation stuff. For the past few days I have been working on this and have been slowly figuring out my problems.

  1. Programming. I bought a few esp-07 off of for under 4 bucks a pop. While there I also bought a ftdi board so I could program them. The ftdi board works fine as a serial monitor but when it comes to programming it just doesn't work. Not sure what the problem was but I couldn't get it to work. Currently I am using an old USB to xbee board and that is working without a problem. If you are trying to program the ESPs and are having issues try a different ftdi device. 
  2. The Arduino IDE is where I have the most programming experience so I am going to stick with it. I know some people hate arduino with a burning passion but for me its simple (for the most part) and what I have the most experience with. Now in a previous post I talked about how to get an arduino with an Ethernet shield publishing and subscribing to MQTT messages. Once you have added the ESP board to the arduino board it is easy to program them as long as you ave the correct pins grounded or 3.3v See the Schematic below. But the PubSub library I was using before does not work with the ESP. Now I found this library. Now the problem with this is both of the libraries, the one I use with the Ethernet shield and the one I am now using both use pubsub. So the arduino IDE picks the one it thinks it should use which causes problems. I just removed the original one for now and have not tried the new one with the Ethernet shield. 
  3. Mosquito MQTT. With the Ethernet shield and the rpi I had no issues with the mosquito install. Now however with the new library I needed to upgrade mosquito. The code to install the new version is below.  Got the code from
    sudo apt-key add mosquitto-repo.gpg.key
     cd /etc/apt/sources.list.d/
    sudo wget
    sudo apt-get update
    sudo apt-get install mosquitto