Device to Database – Week 3 – Sensor Values over MQTT

This past week I set up a set of sensors attached to an Arduino MKR 1010 which I connected to my home WiFi network. The set up was designed to be plugged into a wall and send sensor information to an MQTT broker collecting the data from my classmate’s and my projects during the week between classes. 

Plant Sensor Setup with Arduino MKR 1010 and ENV Shield
Plant Sensor Setup with Arduino MKR 1010 and ENV Shield

My class was on Thursday, and Friday night was the first time I had the opportunity to write the code and set up the device. The code written for the Arduino and sensors (via a MKR ENV Shield and attached soil moisture sensor) asked for the readings for temperature, humidity, pressure, illuminance, UVA, and UVB every 30 minutes. A while after plugging it in, I noticed the amber light blinking on the Arduino, so after restarting it and getting the light, I changed it to 15 minutes, thinking it might be timing out the connection somehow. 

Plant Sensor Setup with Arduino MKR 1010 and ENV Shield in place
Plant Sensor Setup with Arduino MKR 1010 and ENV Shield in place

Over the weekend, I tried unplugging and restarting the Arduino after noticing that the orange light on the MKR 1010 board started blinking a couple of hours after I’d restarted or reset the devide. I eventually re-uploaded the code and changed the data collection time to 5 minutes. 

Screen Shot of MQTT Client Screen. It seemed to always be empty for my device when I opened it up.
Screen Shot of MQTT Client Screen. It seemed to always be empty for my device when I opened it up. Where’s my data??

Every time I would check the MQTT Client after noticing the blinking orange light, it would show there weren’t any readings from my device “device_015”. After restarting the Arduino, I noticed the orange light would turn off and, soon after, the MQTT Client would show it was collecting data from the sensors. 

Successes 

I was able to get my code working fairly easily. Having examples to work with and good documentation to refer to really helps! I based by code on the code we used in class for the file “TemperatureHumidity.ino” and modified it to fit my purposes. Also, I’ve been curious to know how cold it gets in the back spare room where the plants (and my bathroom) are, and this project should finally give me an idea. 

Here’s a link to my code:

TemperatureHumidity_withPlantSensor_Code.ino

Challenges and Lessons Learned

This week, I fell victim to my own knowledge (or, rather, lack thereof.) Two things really tripped me up: 1) the blinking orange light on the Arduino and 2) the fact that I kept seeing in MQTT Client that (it appeared) my device had not been recording data prior to my checking on it. 

Plant Sensor Setup with Arduino MKR 1010 and ENV Shield and the pesky orange light
Plant Sensor Setup with Arduino MKR 1010 and ENV Shield and the pesky orange light
Plant Sensor Setup with Arduino MKR 1010 and ENV Shield and the PERSISTING pesky orange light
Plant Sensor Setup with Arduino MKR 1010 and ENV Shield and the PERSISTING pesky orange light

 

 

 

 

 

 

 

 

As mentioned above, I reset/restarted the device many times over the long weekend. I even restarted my WiFi router and modem… all this because of the two things above. I now see that my lack of understanding the full situation, combined with juuuuuust enough experience to be dangerous, meant that I assumed the blinking orange light meant was a problem when it wasn’t. 

I assumed the orange right was because:

  • there was a problem that, like many IT problems, could be solved by unplugging the device for 15 seconds then plugging it back in. 
  • there was a problem that, like many other IT problems, could be solved by holding down a reset button on the device for 10 seconds. 
  • the connection was timing out (so I made the sending of data more often.)
  • the code was wrong (so I double checked the code and hoped re-uploading it when I changed the timing in the code would help.)
  • the connection was failing because the modem/router didn’t like the new device (so I restarted everything all at once.)

I after trying all that I now believe my lack of understanding of the hardware and the MQTT Client (which reinforced the idea that the orange light meant “problem.”) It also helped that I left the MQTT Client running in the background while I worked on some other homework and noticed it was still recording data although I had just noticed the orange light was flashing when I went into the other room. 

Also, in terms of challenge areas, I wasn’t able to use the HTML monitoring pages to load from home, though I’m not sure why or what I need to change to get it to work from home. 

Summary

This was a fun activity which took a bit more attention than necessary due to some self-inflicted challenges. In the end, it was a good reminder to be patient and take a step back when you feel you’re stuck. In my case, not understanding that the orange light wasn’t a warning/error light or that MQTT Client (or at least my settings) doesn’t show data recorded before logging in were two things working in tandem to lead me to believe there was a problem when it seems there wasn’t. Fortunately, I didn’t give up—even when Google couldn’t tell me the answer—and kept monitoring the situation. Patience *is* a virtue… one I’ve been working on for decades. 

I’m now looking forward to seeing how the data turned out—and to finding out how cold really it gets in the spare room when I go to the bathroom at night!