Weekend Snack: Reviving the IOT saga
It's been a year and a half since I last worked on a wireless module to control my in home devices. I've done my college project on the same, and honestly speaking, it was one of the most exciting project I've done. Wanted to repeat the same using a better approach to overcome the drawbacks I had back in college. One, I did not have access to the hardware that would give me the confidence to trust on my devices that they'd respond as expected whenever I want them to. This was one of the only reasons that I, or my project mate had to travel back and forth to New Delhi every now and then. The other factor dragging us behind was the limited amount of money that could be spent on hardware resources.
That was until this year I started working on it again. Gathered all the equipment I needed. I first tried replicating what I had done in the college using an ESP8266 wifi shield and an arduino, but unfortunately, after multiple attempts, the ESP failed to respond as expected. I have a feeling that this is most probably due to the unmet power requirements that the ESP wants. The shield is supposed to work at a precise voltage of 3.3V and is highly unreliable otherwise. As a result, I couldn't get any output from the ESP shield. The task of setting everything up on the breadboard only to find that it's all in vain was quite frustrating and my patience was about to reach its limit in the beginning of this month. I was totally thinking of switching to a raspberry pie to build my wireless module, but the thought of switching to an expensive hardware, when your primary aim is to build a budget device, is completely irrelevant.
It was till this week that I had a ray of hope that could get that zeal to build a robust wireless module back again. While scrolling through a feed, I came across this amazing microcontroller/module that I had been ignoring completely during my college life. NodeMCU (ESP12E) is something that could solve my purpose. Went through the specifications and voila, it was the exact thing that I needed. A wireless module capable of running an Arduino based code that could be put into action using a wifi. I ordered it instantly and to my surprise, the thing does not have power issues as everything is soldered on the same mesh on the board.
Upon receiving the module, as soon as I plugged it into my system, I faced another issue. The Arduino IDE could not detect the port the module was plugged into. This was strange. Never have I ever faced a problem with the port not being detected. Searched for online solutions of the same issue and realised that a driver needs to be installed for the device to interact with the machine using a serial communication protocol. Moreover, the manufacturer had stated the requirement for the driver at the back of the device as well. I didn't want to just go ahead and install the driver, because of two main reasons. One, the driver was said to have crashed Sierra. Although I was on High Sierra, I still didn't want to risk bricking my system. Two, the driver was from an unknown source (at least I couldn't rely on the source personally). Hence I didn't want to risk my privacy being hindered by a driver that I couldn't trust. A wise man advised me to use a virtual machine with the OS of my choice.
That was it! I had everything figured out (well, that's what I thought :P ). Went ahead and started a virtual machine in VirtualBox with Ubuntu as the operating system. Installed the drivers for linux and plugged in the device. And bam! The device got detected by the operating system. This was a huge win, frankly speaking! Next, loaded a dummy code for setting up wifi on the device and tested it. Well, as you'd expect, I could see a stream of garbage characters being output from the device. This was a let down, an expected, but annoying let down. Also, my device would reset unexpectedly throwing an RST4, bootmode(3,4) or bootmode(1,7) error. I didn't know what that meant, and after searching some of the threads suggested that it could be a power issue, or a firmware issue. I did not want a power issue after going through all the hassle all over again. I could deal with the firmware issue though. Flashing the firmware was something I had done during my college life, and even in my professional life. At this point I'd like to mention an outstanding feature that the developers of NodeMCU have given to the community. The ability to provision custom builds of the branch of your choice, or the desired release number of your choice. In better words, you could choose the build of your choice and provision it instantly by entering your email address. The build will start instantaneously and you'll receive email notifications of the status of your build. In the end, you could just download the bin file from the link that is mailed to you after completion of the build and use it. I provisioned the last release build and downloaded the bin file, flashing it onto my device using esptool. The firmware flashed just fine and I could see the correct version number being detected by ESPlorer. Uploaded my code back again and damn! It still threw the same error.
It'd already been around 3 in the morning and I wasn't able to have a simple wifi scan program running on my device. I don't know how I gathered the courage to start all over again, but somehow I did. I just uploaded a simple hello world program to my device, just to see if it still gave those reset errors. This was to ensure me that the possibility of having a power issue was low. Uploaded my program to the device and tested it. It ran!
Next I uploaded a simple LED blink program to my device. It worked. To my dumbness, I was using the incorrect LED pin to test the blink program on the device till now. Anyway, that was quite encouraging. I then tried to upload a simple wifi program. But this time, I didn't choose an example sketch as is from the IDE. I modified it to use just ESP8266Wifi.h library and nothing else (of course I took help from the internet). It worked!!!!!
So, the reason for the unexpected resetting of my device was not a power issue, rather it was a bad code that I had uploaded to my device that it just couldn't understand and since the ESP wasn't able to run the code, the watchdog reset my device.
I now have a rough implementation of my wireless home control setup. Currently, I have just one sensor responding to me wirelessly. The aim is pretty far though. But sooner than later, I'm going to complete it.
Oh and an update on the status of my dapp. The basic working dapp is done. It's a simple vote for a candidate platform where you could cast a vote to a candidate from a list of available ones. The user can cast a vote, and see the number of votes received by a candidate at the moment. There's some good learning involved there too.
Until next post!
Cheers!
That was until this year I started working on it again. Gathered all the equipment I needed. I first tried replicating what I had done in the college using an ESP8266 wifi shield and an arduino, but unfortunately, after multiple attempts, the ESP failed to respond as expected. I have a feeling that this is most probably due to the unmet power requirements that the ESP wants. The shield is supposed to work at a precise voltage of 3.3V and is highly unreliable otherwise. As a result, I couldn't get any output from the ESP shield. The task of setting everything up on the breadboard only to find that it's all in vain was quite frustrating and my patience was about to reach its limit in the beginning of this month. I was totally thinking of switching to a raspberry pie to build my wireless module, but the thought of switching to an expensive hardware, when your primary aim is to build a budget device, is completely irrelevant.
It was till this week that I had a ray of hope that could get that zeal to build a robust wireless module back again. While scrolling through a feed, I came across this amazing microcontroller/module that I had been ignoring completely during my college life. NodeMCU (ESP12E) is something that could solve my purpose. Went through the specifications and voila, it was the exact thing that I needed. A wireless module capable of running an Arduino based code that could be put into action using a wifi. I ordered it instantly and to my surprise, the thing does not have power issues as everything is soldered on the same mesh on the board.
Upon receiving the module, as soon as I plugged it into my system, I faced another issue. The Arduino IDE could not detect the port the module was plugged into. This was strange. Never have I ever faced a problem with the port not being detected. Searched for online solutions of the same issue and realised that a driver needs to be installed for the device to interact with the machine using a serial communication protocol. Moreover, the manufacturer had stated the requirement for the driver at the back of the device as well. I didn't want to just go ahead and install the driver, because of two main reasons. One, the driver was said to have crashed Sierra. Although I was on High Sierra, I still didn't want to risk bricking my system. Two, the driver was from an unknown source (at least I couldn't rely on the source personally). Hence I didn't want to risk my privacy being hindered by a driver that I couldn't trust. A wise man advised me to use a virtual machine with the OS of my choice.
That was it! I had everything figured out (well, that's what I thought :P ). Went ahead and started a virtual machine in VirtualBox with Ubuntu as the operating system. Installed the drivers for linux and plugged in the device. And bam! The device got detected by the operating system. This was a huge win, frankly speaking! Next, loaded a dummy code for setting up wifi on the device and tested it. Well, as you'd expect, I could see a stream of garbage characters being output from the device. This was a let down, an expected, but annoying let down. Also, my device would reset unexpectedly throwing an RST4, bootmode(3,4) or bootmode(1,7) error. I didn't know what that meant, and after searching some of the threads suggested that it could be a power issue, or a firmware issue. I did not want a power issue after going through all the hassle all over again. I could deal with the firmware issue though. Flashing the firmware was something I had done during my college life, and even in my professional life. At this point I'd like to mention an outstanding feature that the developers of NodeMCU have given to the community. The ability to provision custom builds of the branch of your choice, or the desired release number of your choice. In better words, you could choose the build of your choice and provision it instantly by entering your email address. The build will start instantaneously and you'll receive email notifications of the status of your build. In the end, you could just download the bin file from the link that is mailed to you after completion of the build and use it. I provisioned the last release build and downloaded the bin file, flashing it onto my device using esptool. The firmware flashed just fine and I could see the correct version number being detected by ESPlorer. Uploaded my code back again and damn! It still threw the same error.
It'd already been around 3 in the morning and I wasn't able to have a simple wifi scan program running on my device. I don't know how I gathered the courage to start all over again, but somehow I did. I just uploaded a simple hello world program to my device, just to see if it still gave those reset errors. This was to ensure me that the possibility of having a power issue was low. Uploaded my program to the device and tested it. It ran!
Next I uploaded a simple LED blink program to my device. It worked. To my dumbness, I was using the incorrect LED pin to test the blink program on the device till now. Anyway, that was quite encouraging. I then tried to upload a simple wifi program. But this time, I didn't choose an example sketch as is from the IDE. I modified it to use just ESP8266Wifi.h library and nothing else (of course I took help from the internet). It worked!!!!!
So, the reason for the unexpected resetting of my device was not a power issue, rather it was a bad code that I had uploaded to my device that it just couldn't understand and since the ESP wasn't able to run the code, the watchdog reset my device.
I now have a rough implementation of my wireless home control setup. Currently, I have just one sensor responding to me wirelessly. The aim is pretty far though. But sooner than later, I'm going to complete it.
Oh and an update on the status of my dapp. The basic working dapp is done. It's a simple vote for a candidate platform where you could cast a vote to a candidate from a list of available ones. The user can cast a vote, and see the number of votes received by a candidate at the moment. There's some good learning involved there too.
Until next post!
Cheers!
Comments
Post a Comment