Just a "Thank You" and my project update
Posted: Wed Dec 21, 2016 6:48 pm
Most posts in a forum like this will be about problems, so I thought I'd take a minute to just say “Thanks” to the developers of MicroPython, and to the posters here who contribute to help out others, and to speak to my little successes. So... “Thanks!”.
Just a little background on what I've done with my little project so far. I was interested in monitoring some of the appliances in my home. Most importantly, my well pump. It had developed an unseen, underground leak a few years ago. The pump is at the bottom of our well, totally silent, and I didn't notice until the leak got so bad that the pump was running 24/7 and couldn't maintain pressure. I had a large electric bill that month, and a lot of wear/tear on the pump - I wish I caught it sooner!
I started seeing references to inexpensive micro-computers (Raspberry Pi, etc), with GPIO, and decided it was time to try something. Then I came across these ~ $8.50 ESP8266 boards, with flash, Wi-Fi, and GPIO/ADC. Wow!
But most of these boards used some rather unique programming language, or C or Java (I'm not very good at either of those). I really preferred working in a more 'BASIC-like' language (I had used HP-'Rocky Mountain BASIC' for instrument control many years ago, plus some scripting on UNIX systems), and also something that would useful for other computer scripts I might want to tackle. So I saw MicroPyhton - AH-HAH! Python is available for scripting on my computer, the learning curve is not bad at all for someone like me.
So I got a board, verified it seemed functional, and re-flashed it with MicroPython. I just built my program a block at a time, learning as I went. I've had a fairly full-featured implementation working for a few weeks now, and it seems very stable, really only one glitch/crash that wasn't something easily attributed to my own code fault. And this is still with very little error checking (I will add as I go along).
If anyone cares, my program is just a loop, checking GPIO status every 6 seconds, with some debounce logic. I connected a 220/110V USB output 'wall wart' across the 220V pump circuit with a voltage divider and LED on the ~ 5V output to provide ~ 2.7V to a GPIO pin when running, 0V when off.
I monitor the status of the GPIO line, and write to a file on flash with the time of each change in state, with the elapsed time of the previous state. And a “Watchdog status” write if there was no action for 30 minutes, just so that when I see a file, I know it was complete, with no dropouts in data collection. I create a new file each day (GMT/UTC to keep it simple), and just append info as it comes in. I blink the LED when I check GPIO, and during data uploads, just to have some visual feedback that the program is running.
During local daytime hours, once an hour the ESP attempts to upload the file to a Python socket program I have running on my computer. If it can't connect (my computer is off/sleeping, or program not running), it will just try again next hour (I did need to error trap that - which I got help from on this forum). When it has confirmation that the older day file(s) have been uploaded, it will delete them. So the files only take up a few KB of flash at most.
Oh, and the 8.6 release really helped me - I was hitting memory limits on loading the program before I re-flashed with 8.6. I've added a fair amount of code since then, and still loading OK.
I'm looking forward to buying a bunch more of these boards, and getting them on my sump pump, fridge, freezer, water heater, furnace, etc. A near-future enhancement on my server side, is to identify any data outside expected limits, and email an alert to me. I've tried the code for that, and it worked with little effort and just a few lines. Fun (well, 'geeky fun') stuff!
I had wondered if I should have just used one of the canned packages for this MQTT, or something? But I kind of wanted to 'roll my own' to learn more at the low level. I also seem to have a lot of RTC clock drift, but I'll tackle that in the new year, and create a new thread if I need help or find anything worth sharing.
Well, enough blabbering - “Thanks” again, and Happy Holidays to all!
Just a little background on what I've done with my little project so far. I was interested in monitoring some of the appliances in my home. Most importantly, my well pump. It had developed an unseen, underground leak a few years ago. The pump is at the bottom of our well, totally silent, and I didn't notice until the leak got so bad that the pump was running 24/7 and couldn't maintain pressure. I had a large electric bill that month, and a lot of wear/tear on the pump - I wish I caught it sooner!
I started seeing references to inexpensive micro-computers (Raspberry Pi, etc), with GPIO, and decided it was time to try something. Then I came across these ~ $8.50 ESP8266 boards, with flash, Wi-Fi, and GPIO/ADC. Wow!
But most of these boards used some rather unique programming language, or C or Java (I'm not very good at either of those). I really preferred working in a more 'BASIC-like' language (I had used HP-'Rocky Mountain BASIC' for instrument control many years ago, plus some scripting on UNIX systems), and also something that would useful for other computer scripts I might want to tackle. So I saw MicroPyhton - AH-HAH! Python is available for scripting on my computer, the learning curve is not bad at all for someone like me.
So I got a board, verified it seemed functional, and re-flashed it with MicroPython. I just built my program a block at a time, learning as I went. I've had a fairly full-featured implementation working for a few weeks now, and it seems very stable, really only one glitch/crash that wasn't something easily attributed to my own code fault. And this is still with very little error checking (I will add as I go along).
If anyone cares, my program is just a loop, checking GPIO status every 6 seconds, with some debounce logic. I connected a 220/110V USB output 'wall wart' across the 220V pump circuit with a voltage divider and LED on the ~ 5V output to provide ~ 2.7V to a GPIO pin when running, 0V when off.
I monitor the status of the GPIO line, and write to a file on flash with the time of each change in state, with the elapsed time of the previous state. And a “Watchdog status” write if there was no action for 30 minutes, just so that when I see a file, I know it was complete, with no dropouts in data collection. I create a new file each day (GMT/UTC to keep it simple), and just append info as it comes in. I blink the LED when I check GPIO, and during data uploads, just to have some visual feedback that the program is running.
During local daytime hours, once an hour the ESP attempts to upload the file to a Python socket program I have running on my computer. If it can't connect (my computer is off/sleeping, or program not running), it will just try again next hour (I did need to error trap that - which I got help from on this forum). When it has confirmation that the older day file(s) have been uploaded, it will delete them. So the files only take up a few KB of flash at most.
Oh, and the 8.6 release really helped me - I was hitting memory limits on loading the program before I re-flashed with 8.6. I've added a fair amount of code since then, and still loading OK.
I'm looking forward to buying a bunch more of these boards, and getting them on my sump pump, fridge, freezer, water heater, furnace, etc. A near-future enhancement on my server side, is to identify any data outside expected limits, and email an alert to me. I've tried the code for that, and it worked with little effort and just a few lines. Fun (well, 'geeky fun') stuff!
I had wondered if I should have just used one of the canned packages for this MQTT, or something? But I kind of wanted to 'roll my own' to learn more at the low level. I also seem to have a lot of RTC clock drift, but I'll tackle that in the new year, and create a new thread if I need help or find anything worth sharing.
Well, enough blabbering - “Thanks” again, and Happy Holidays to all!