(Solved) Arduino code on ESP8266 keep crashing on submitting CPM to Radmon

More
2 years 1 month ago #6038 by 4L7RU157
The code turned out to contain just what I needed, it was just a bit overcomplicated and hard to read by all the if statements. And I always have a bit of a problem gaining oversight with code spread over multiple files (and a lot of extra functionality).

In the morning with a fresh set of eyes I had a much better experience using the code snippet :) got it working and posting to radmon.org just fine.

Is your code custom or based on any existing solution out there? I had a hard time finding a firmware file on the DIYGeiger site or anywhere else.

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #6039 by 4L7RU157

4L7RU157, this may (or may not) help you. It is some bare bones code for the ESP8266/Wemos D1 Mini: https://radmon.org/index.php/forum/howtos-and-faqs/1225-esp8266-wemos-d1-mini-arduino-code-bare-bones-code-verified-working 
 

This topic could (should) be referenced on the https://radmon.org/index.php/software page
 

Please Log in or Create an account to join the conversation.

  • Simomax
  • Simomax's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Nuts about radioactive everything!
More
2 years 1 month ago #6040 by Simomax
'overcomplicated and hard to read by all the if statements'; do you mean all the debug parts? If that, then yes I know. Lots of debug makes it messy and difficult sometimes, but a necessary evil. The debug strings offer commenting also. I generally like to keep as much debugging as I can as this can really help other people if they use the code and are struggling with things. Also with regards to your comment about putting the code on github.... Nah... I really can't be bothered in maintaining something like that for small code. If I was writing code for a nuclear power station, then maybe github would work as a collaboration tool. It takes only a few clicks to copy and paste the code into the Arduino IDE, and then viola! Syntax highlighting! 

It is all my own custom code, with the exception of a few small parts of code originally written by BroHogan (DIY Geiger - I bought one of his GK Radmon units) as the code I posted earlier on this thread is custom code for the GK Radmon. It is only really the PWM HV generation parts of code that I have kept as they are required for that particular hardware. Everything else I wrote from scratch. It isn't that BroHogan's code didn't work (with one exception that I will come to) but it didn't operate in a way that I wanted. The GK Radmon code is designed for very low power consumption and it will go to sleep, wake after 4 minutes and 30 seconds (if I recall) then counts for 30 seconds, submits to Radmon and Thinkspeak and then goes to sleep again. This is great and works fine if that is what you want. I didn't. I wanted a power-hungry always on, always connected, always up-to-date counter where I could display on my mobile phone using Blynk. So I took the functions needed to run the HV on the hardware, and also the Radmon submission part and wrote my own code around those small functions. However, for some weird reason the HTTP code would crash the ESP8266 after an arbitrary length of time. What was happening was the code was freezing at some point in the Radmon submission function and then the watchdog timer would kick in and force a reboot. I never narrowed it down to exactly what, but other people were suffering similar issues with other projects. So I found a small example of different code, tried it and it worked, so re-wrote the Radmon submission function by 'get'ting instead of 'post'ing. It worked. Has worked since so I kept it. I do need to do another post on this at some point.

The new code that I wrote this morning is the same code running on my GK Radmon (my custom code) but about 90% thinner. I took out every function except for the absolute bare essentials for counting and submitting. It may made a nice foundation for other people to write their own code upon, or just use as is.

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #6041 by 4L7RU157
@Simomax fully understandable :D I do appreciate your effort to offer others a bare-bones starting point :)

I uploaded my code to github, hope it helps others. Although I did not remove the debug statements and just took what I needed :P
https://github.com/dikkedimi/RadMon-lolin32-oled

Please Log in or Create an account to join the conversation.

  • Simomax
  • Simomax's Avatar Topic Author
  • Offline
  • Moderator
  • Moderator
  • Nuts about radioactive everything!
More
2 years 1 month ago #6042 by Simomax
@4L7RU157: Are you using an ESP32? If so, did the Radmon submission code just work without having to change anything?

Also, looking at your code it looks like you are using a small OLED display. It looks like you are updating the display every time the loop runs. That's generally bad mojo. You will be tying up precious CPU cycles, and it may even be using an interrupt for the SPI/I2C bus which may cause other things to hang up whilst the display is updating. It would be better to put the display code in a function and then call that function say every 1000ms or 5000ms, or whatever. Obviously this will still tie up the CPU a little, but doing it every 1000ms is way better than every loop.

Another thing I learned about the small OLED displays is they wear out, and faster than you might think. A thermostat I made about 2 years ago has the OLED always on, and that lasted less than 12 months before pixels started to fade, and now at 2 years the display is pretty much ruined. Not a biggie as they are cheap, but if you want it to last then maybe think about turning it off after say 30 seconds or so. If you look at the bare-bones arduino code I wrote you can see that I have done just that for both calculating the CPM and sending to radmon. They are both contained within their own function and the loop counts the millis. When it reaches 1000ms it will call the CPM function, same for sending to radmon. For larger programs, like the custom FW I wrote for the GK Radmon, I use the 'simple timer' library. It simply allows you to setup multiple timers and they fire automagically and will simply call the function that is defined. You can also stop and start the timers dynamically which is really handy - saves many if statements! 

Please Log in or Create an account to join the conversation.

More
2 years 1 month ago #6043 by 4L7RU157
Yeah, I had an ESP32 devboard (lolin32) lying around. Couldn't use it for anything useful like TinyGS because it does not have exposed SPI pins to connect to a lora module. So I opted to use it for this instead.

I ported my previous custom code from when I was running it on an ESP8266/ESP12, that code didn't submit to radmon.org, just published on mqtt so I could use it with openhab :P My openhab borked so I switched to home assistant and am remodeling a lot of old projects :)

With all the unrest in Ukraine I thought it might be nice to have it log to Radmon. Your code worked without much hassle. I just had to do a little commenting out and adjust one or 2 variables to use the array I defined globally.

Was getting zeroes as values on radmon and then figured out I was sending the mS/h value, so always below 1 :P changed array index and voila, it worked.

Not a programmer by trade but I feel like I'm slowly gaining more insight after all these years of copy pasting and asking my more gifted friends for help :oops:

To-Do's: (no specific order)
- update display in a thread (high priority)
- invert display colors every 12 hours (like tinyGS does) mid priority
- enable sound with a relay above a certain threshold (nice to have)
- home assistant integration, alarms, notifications and such.

One other thing is I have shielded the GM tube with a piece of aluminium pipe (properly insulated with nice 3D printed bushings), which helps with light sensitivty, but it also influences readings. Any thoughts on this? it is pretty thick aluminium (15mm pipe, 12mm internal diameter)

Please Log in or Create an account to join the conversation.

Moderators: Gamma-Man
Time to create page: 0.235 seconds
Powered by Kunena Forum
Everything's free. Please support us by considering a donation. Log in first!
Solar powered Raspberry Pi 4 server stats: CPU 26% Memory 13% Swap 12% CPU temp=52.5'C Uptime 18 Days