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 "Thank You" and my project update
Re: Just a "Thank You" and my project update
Hi NTL,
Your project sounds great. I'll also send out a "thank you" to the MicroPython community for all of the hard work and excellent results.
Thanks,
J
Your project sounds great. I'll also send out a "thank you" to the MicroPython community for all of the hard work and excellent results.
Would you care to share any details and/or code on how you upload and download the data with sockets? I'd like to do that from my esp8266 and haven't looked into the socket library yet to try and figure out how.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.
Thanks,
J
Re: Just a "Thank You" and my project update
Also want to echo a big thank you to the micro python community. Learning about this exciting new platform has been extremely fun!
If are looking for a socket library, feel free to pilfer the TCPServer class from here.
Alternatively, you could just implement an API handler and do your uploads and downloads via REST. The rest will be done for you.
If are looking for a socket library, feel free to pilfer the TCPServer class from here.
Alternatively, you could just implement an API handler and do your uploads and downloads via REST. The rest will be done for you.
Re: Just a "Thank You" and my project update
Well, I will be embarrassed to show my code, I'm just learning sockets and am only slightly familiar with Python & MicroPython. But I'll see if I can strip that away from the other code, and post the basics. I found a lot of the documentation confusing for a beginner like me I need examples to learn from. So maybe my code can help you.jpj wrote:Hi NTL,
Your project sounds great. I'll also send out a "thank you" to the MicroPython community for all of the hard work and excellent results.
Would you care to share any details and/or code on how you upload and download the data with sockets? I'd like to do that from my esp8266 and haven't looked into the socket library yet to try and figure out how.
Thanks,
J
I'll try posting it today in a new thread, but be warned, I can't really fully test it, I only have one ESP8266 right now, and it's busy running the full code. I plan to buy more boards soon so I can experiment more easily.
I'm sure others will find the code ugly and lacking in proper error handling, etc, but it is working (in my application). Maybe I'll get some good tips to improve it.
I see the follow up post from fdushin - that's probably the correct way to go about it, but as a beginner, I can't make heads or tails out of it, sorry. And for me, part of this was to learn how it works at a little lower level.
Re: Just a "Thank You" and my project update
I'm in the same placeWell, I will be embarrassed to show my code, I'm just learning sockets and am only slightly familiar with Python & MicroPython. But I'll see if I can strip that away from the other code, and post the basics. I found a lot of the documentation confusing for a beginner like me I need examples to learn from.
Don't be too hard on yourself. Everybody was a beginner at some point. I'm definitely a beginner and when I look at my early code it amazes me that it ever ran at all (see #6 below)I'm sure others will find the code ugly and lacking in proper error handling, etc
The Six Stages of Debugging
1. That can't happen.
2. That doesn't happen on my machine.
3. That shouldn't happen.
4. Why is that happening?
5. Oh, I see.
6. How did that ever work?
Re: Just a "Thank You" and my project update
OK, here you go...jpj wrote: Don't be too hard on yourself. Everybody was a beginner at some point. I'm definitely a beginner and when I look at my early code it amazes me that it ever ran at all (see #6 below)
http://forum.micropython.org/viewtopic.php?f=16&t=2804
Hah - I actually came across some very old code I wrote, on a project where it was important to keep it clean, maintainable and robust. I was actually surprised to see that I thought it looked pretty good, even in hindsight. Some other stuff I've done - not so much!
http://forum.micropython.org/viewtopic.php?f=16&t=2804
Last edited by NTL2009 on Thu Dec 22, 2016 9:56 pm, edited 1 time in total.
Re: Just a "Thank You" and my project update
I recently moved to a different timezone. I had built an LCD clock based on Arduino about 4 years ago that needed the daylight savings time auto-adjust code updated. I thought it would be a 15 minute task, but the code was so ugly I did a 80% rewrite.Hah - I actually came across some very old code I wrote, on a project where it was important to keep it clean, maintainable and robust. I was actually surprised to see that I thought it looked pretty good, even in hindsight. Some other stuff I've done - not so much!
A friend of mine used to say "never look back." He may have had a point there. Thanks, I'll take a look at your code.
Cheers,
J
Re: Just a "Thank You" and my project update
I'm interested in learning how to improve the quality of my code too. I only discovered uPython a couple of weeks ago and have limited embedded software experience. I'm developing an IOT business monitoring water pumps for inefficiency operation and the PyBoard is an excellent platform for developing this type of application.
I'm also interested in hearing from anyone interested in earning a bit of extra cash by working with me helping me accelerate my uPython development skills and capacity.
I'm also interested in hearing from anyone interested in earning a bit of extra cash by working with me helping me accelerate my uPython development skills and capacity.