Notifications
Clear all

ESP32 for IoT for Automobiles

42 Posts
3 Users
5 Likes
4,136 Views
(@jfabernathy)
Member
Joined: 3 years ago
Posts: 141
Topic starter  

After reading Bill's latest newsletter I thought I'd start a discussion on a related topic that is giving me fits. I have my RV in the backyard in a winterized state, but I'd like to monitor temperature and humidity to see how cold and damp it really gets inside. And with nothing else to do this quarantined winter, it's a good project. I found a tutorial article where this task was done on an ESP32 using the IoT protocol MQTT and that's what I wanted to use. I already had some Raspberry Pis doing this in remote parts of the house and I have another Raspberry Pi running NodeRed, Mosquitto, influxDB, and Grafana to collect, store and display the data. 

Using the ESP32 seemed logical because it is current yet with some age so most of the issues are worked out by other, I hoped.

So my problem is how to debug this in the real world.  Since the ESP32 does not work with CircuitPython, I used Arduino IDE and PlatformIO. Both work very well and it took me a short time to modify the tutorial example to match my hardware and data format. I tested for days running on the dining room table with power from a Lipoly battery and a LC709203F battery monitor. I'd recharge every day when needed. 

I was satisfied that it was working and moved the setup to my RV but added a USB charger cable because the RV has USB outlets and the RV has solar to keep the batteries topped off.

After 2 days of flawless operation, it just stopped transmitting any data.  It's such a pain to open up the RV to go reset it, I going to plan how to find the problem and setup for that before I go out to reset it. 

So I'm looking for how to debug this. I have debug serial output built in. All I would have to do is setup a Raspberry Pi to read the UART of the ESP32 and capture the information. But I'm not sure anything useful would come from that capture since I already think I have most of the errors captured, but who knows.

I'm kind of thinking about a watchdog timer external to the ESP32. Something very simple that if you don't reset it's timer via a GPIO from the ESP

32, it would yank the reset line on the ESP32. From my testing that seems like a simple thing that would activate every few days at most.

Since I'm using Deep Sleep mode, I had to write the code as a 1 pass, no loop program. So coming out of reset versus coming out of deep sleep is the same, particularly since I'm not using the NVM that is powered during deep sleep.

So what do other think about how to solve this? 

 

If your code won't compile, have another glass of bourbon. Eventual the problem will be solved.


   
Quote
byron
(@byron)
No Title
Joined: 5 years ago
Posts: 1121
 

@jfabernathy

that seems to be a pesky type of problem where there could be a plethora  of reasons for the problem. I thank a watchdog circuit could well be a solution.   Just in case you need it I link to a youtube video on creating such a circuit.

If you are using the older ESP32 boards it maybe better to consider using micropython instead of circuitpython,  though not for the ESP S2 variety.  My ESP32 TinyPico linked to a tmp117 temp sensor worked for over a month without an issue a while back, though I've now re-purposed my TinyPico for another project.  But I think you are using the ESP S2 board so this probably will not help.  However, whist the TinyPico is a tad expensive it may also be worth considering getting a cheapo ESP32 board and running micropython as you can pick up these boards for just a few $ to get your project underway whilst waiting for the ESP S2 infrastructure to mature.


   
ReplyQuote
(@jfabernathy)
Member
Joined: 3 years ago
Posts: 141
Topic starter  

@byron I left out some details that may have been confusing particularly since I have other post talking about ESP32-S2.

Originally I did this project with an Adafruit Metro ESP32-S2 and with that board CircuitPython is recommended over Arduino IDE. The ESP32-S2 has the PSRAM needed for CircuitPython (CP) that the EPS32 does not.  

So with the ESP32-S2 I could not use Arduino IDE and still can't--major issues.  The only problem I had using CP was the MQTT libraries were not there yet. So I had to use HTTP and I found enough examples to allow me to do that.  My NodeRed setup had 2 inputs to my influxdb output, one for MQTT and one for HTTP.  So I got the Metro ESP32-S2 working in the RV except it would stop transmitting data some number of hours after working successfully in the house for days. In my debug effort I put counters in the NVM called alarm.memory in CP deep sleep world.  I found that the Metro was coming out of deep sleep with reset status instead of Deep Sleep status occasionally. So I started working that problem with the Adafruit CP team on Github.  After a few weeks we now have that problem diagnosed to being related to a Brownout reset setting.  It maybe a hardware issue and can be worked around in the IDE by disabling Brownout reset capability.  I built from master a version of CP with Brownout reset turned off and that problem is basically solved.

SO that's a long way round to saying I have the same issue with both ESP32 with Arduino and ESP32-S2 with CP with my application. They both work fine for days in the house, but fail after from hours to days in the RV. 

If it was WiFi strength related I guess I could test in the house by making cardboard boxes covered with some aluminum foil to see what that does.  When I ran a scan test on the APs in both the house and RV, I see nothing lower than -48db in the RV.  And it's supposed to just deep sleep if it gets an error and start over again.

Thanks for he video reference.

 

If your code won't compile, have another glass of bourbon. Eventual the problem will be solved.


   
ReplyQuote
(@jfabernathy)
Member
Joined: 3 years ago
Posts: 141
Topic starter  

After reviewing the video above and a lot of other WDT resources, I implemented WDT on both my ESP32 and ESP32-S2; one in Arduino and one in CircuitPython. The one on the ESP32 triggered after 23 hours, reset the system and everything recovered perfectly.  I only lost one minute's worth of readings. I track whether the WDT triggered by a NVM counter that increments on every run unless the the WDT triggers and the whole part resets.

I'm still waiting for the ESP32-S2 WDT to trigger.

Since the programs are single pass, then Deep Sleep, there is no loop so I don't feed the watchdog except at the beginning. I set my deep sleep timer for 60 seconds and my WDT for 70 seconds.

Works great.

If your code won't compile, have another glass of bourbon. Eventual the problem will be solved.


   
ReplyQuote
(@jfabernathy)
Member
Joined: 3 years ago
Posts: 141
Topic starter  

Now that I've been running my ESP32 Temperature and Humidity monitoring board for a few weeks, I'm really glad I have the WDT implemented. It can run for 4-5 days and then reset and start over. I added a loop counter that gets incremented and stored in NVM that gets powered in Deep Sleep on the ESP32. I post the counter along with the environmental data via MQTT.  So when that counter goes back to zero I know there has been a triggering of the WDT. 

Everything keeps going and I, at most, miss one minute of posted data.

If anyone wants to see the final code it's on my github for this project:

https://github.com/jfabernathy/MQTT-humidity-and-temperature

 

If your code won't compile, have another glass of bourbon. Eventual the problem will be solved.


   
byron and huckOhio reacted
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@jfabernathy

I have not jumped into Node Red yet but have decided it's overdue for me to take a look.  Can you recommend any tutorials?

I do have Node Red installed on a RasPi 4 along with the mosquito broker.  I'm interested in being able to logged received messages to a database for later retrieval and have looked at your GitHub link.  Not sure how to look at the Node Red "Flow" that you have on the GitHub site.

Any help appreciated.

SteveG


   
ReplyQuote
(@jfabernathy)
Member
Joined: 3 years ago
Posts: 141
Topic starter  

@codecage I got interested in NodeRed when I saw the IOTStack video that Andreas did a while ago. It basicallly took a freash RPI4 with RPI OS on it and had a script to build Docker with the containers for Mosquitto, NodeRed, InfluxDB, and Grafana.  I also have Portainer to help manage stuff in the Docker system.  There is a great how to for the IOTStack:

https://sensorsiot.github.io/IOTstack/Getting-Started/

As far as viewing my NodeRed Flow, you can copied it into the clipboard and do a NodeRed Flow import and paste it into the a new flow.  That way you can examine it.  I do the heaving formatting in the EPS32, ESP32-S2, and the Raspberry 3B+ programs. InfluxDB takes care of the time-stamping. the IOTStack was easy.  Grafana took a while to understand, but I got it now. InfluxDB command line is hard just like MySQL.

Let me know if you need more information.

 

If your code won't compile, have another glass of bourbon. Eventual the problem will be solved.


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@jfabernathy

Well as with Node Red I haven't delved into Docker either.  I can't seem to see how it fits into the picture.  Is it a requirement or does it just somehow makes things easier?

Will look at the link you suggested and maybe that will get me pointed in the right direction.

SteveG


   
ReplyQuote
(@jfabernathy)
Member
Joined: 3 years ago
Posts: 141
Topic starter  

@codecage To me the Docker was dirt simple.  I did a fresh install of RPI OS Desktop, then run the script to install IOTStack.  I chose, mosquitto, nodered, influxDB, grafana, and Portainer.

There is a built in backup and restore feature so that once you configure your containers, you can backup their configurations and data to a server somewhere.  All the data and config is external to the containers.  So for a rebuild, you start fresh, run a script and restore all the config and data from a server.  That's what sold me.  The video that Andreas did talked about that. 

BTW, The coolest thing I did recently was use an Adafruit Magtag which is a eink screen bolted to an ESP32-S2 board.  I have a program that once every 5 minutes goes to my Nodered and request the most recent environmental readings from the influxdb and then it displays those reading on the eink display.  It then deep sleeps. The display stays constant for 5 minutes until the next loop. It runs for a week on a little LiPoly 420mah battery. I may have included that code on the github site

As to tutorials on NodeRed. There are a lot and I just watch what interest me.  I find this guy on youtube does a lot of IOT stuff and nodered is in half of them.

https://www.youtube.com/c/stevecope/videos

 

If your code won't compile, have another glass of bourbon. Eventual the problem will be solved.


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

OK, I guess you could say I'm not a real "Happy Camper!"

I had a perfectly setup RasPi 4 with SSH for login, NodeRed, and Mosquito up and running, but no real knowledge of how to use them, so decided to try this IOTStack/Getting-Started that was pointed to above.  Well shame on me!  Not having any other spare SD cards just laying around that I wanted to sacrifice I went ahead and formatted the one I was using, reinstalled a fresh install of RasPi OS, and then tried following the "Install" from the above link.

Well guess WHAT?  I got tons of errors that were somewhat totally useless at the moment while trying to get the IOTStack installed, but since there was a line in the installation text that mentions not to worry about all the errors/warnings I thought things were going along OK.

When I finally figured out how to exit the setup, it appears that docker is indeed running but nothing else appears to be there.  In other words, nothing appears to be 'docked."

I guess tomorrow I'll start over and try to get back to where I was earlier today.  But I'm going to use the rest of the day to cool off.

If anyone could suggest an installation set of instructions that actually work then that would be greatly appreciated.

SteveG


   
ReplyQuote
(@jfabernathy)
Member
Joined: 3 years ago
Posts: 141
Topic starter  

Make sure you watch when to use Sudo and not.

If your code won't compile, have another glass of bourbon. Eventual the problem will be solved.


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

Was very careful with that, but did not use it unless the instructions said to use it.  That's part of what I thought was a failing of that whole thing.  There was a waring about that and then away they went.  I would have thought the instructions would have said "Don't use Sudo here" or "Use Sudo here" along with each step.

SteveG


   
ReplyQuote
(@jfabernathy)
Member
Joined: 3 years ago
Posts: 141
Topic starter  

@codecage Tomorrow, I'll take another SSD and put a fresh RPI OS on it and see if I can get IOT stack back up on it. I'll let you know what I find.  I know that their are a few containers that got updated and you might have to lock them into particular versions. I've been getting help on the Discord channel for IOTStack.  It's linked in the Wiki

 

If your code won't compile, have another glass of bourbon. Eventual the problem will be solved.


   
ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 5 years ago
Posts: 1037
 

@jfabernathy

Thanks for the assistance.  Will take another look at it tomorrow and use the Docker website to see if the apps will load from there.

SteveG


   
ReplyQuote
(@jfabernathy)
Member
Joined: 3 years ago
Posts: 141
Topic starter  

If you use IOTStack. You can't install Docker yourself. There  are some updates needed in the docker compose.yml file. I'm working on it.

If your code won't compile, have another glass of bourbon. Eventual the problem will be solved.


   
ReplyQuote
Page 1 / 3