Thursday, March 26, 2020

Time Lapse Camera

I decided I needed a time lapse camera video of the bus build. I have two of the ESP32-CAM modules from AI Thinker.

To flash the ESP32-CAM I hooked a FTDI USB-serial adapter as:

5v  -> 5V  (pin 1 sorta)
GND -> GND (pin 2 sorta)
Tx  -> UOR
Rx  -> UOT
IO0 - GND during flash, press reset once first


I first tried the example in the Arduino IDE for it. It seems OK so I looked for an example time lapse. I found https://www.bitsnblobs.com/time-lapse-camera-using-the-esp32-cam/ His code is called E8. All I changed was to un-comment the correct camera definitions.

It boots, takes a photo, writes it to the SD card and sleeps for about 15 seconds. Then repeats. Sounds just right.

I then found a micro SD card that I could reformat to FAT32.

To use it, it needs a mount. There is a mounting box at https://www.thingiverse.com/thing:3652452 that fit fairly good. The hole for the power wires is in the wrong corner for me so I just left the cover off.




I powered it with an 18650 battery direct to the 3.3v input pin. and mounted it to the forward bulkhead of the bus. I try to remember to take out the battery when I stop working for the day and put it back in the next time.

Converting the photos to a video was trivial in linux:


  pot$ ffmpeg -pattern_type glob -i "IMG*.jpg" ~/tmp/output4.mpeg
or
  pot$ mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -o timelapse.avi -mf type=jpeg:fps=12 mf://@frames.txt

Here is today's video:


Saturday, March 14, 2020

Air Purifier Managed by Tasmota

My daughter has been suffering with allergies this spring. I decided to install a new air Purifier in the house. It may also help with bacteria/virus control too. It is a UV light in combination with an ionizer. It installs in the heater air duct. It was easy to install, cut a 3 inch hole in the duct after the fan and screw it into the hole. Install the provided transformer inside the heater and plug it in.

The air purifier installed.

For the size of this house based on square footage, it needs the fan to run at least 20 minutes at a time and repeat every hour regardless of whether the heater is on or not. I didn't have a timer and Amazon wanted way TOO much! I did find a dual relay module in my extras box and an esp8266, NodeMCU V0.9. I've had them quite a while.

I had heard of Tasmota, an IoT home automation software for ESP based controllers. I had not played with it before. I could have just written a program and webpage, but I usually do not add the extra code for robustness. I hoped that tasmota did. I downloaded it and flashed the ESP. It only took a couple days to find the little nuances that stopped it from doing what I wanted (without reading all the docs!). I was caught by the desire to not use MQTT or any cloud services. Finally I found that "on system#boot" does not work without MQTT and mDNS set, so it needed a patch, I downloaded tasmota_8.1.0.10.bin from http://thehackbox.org/tasmota/


The dual relay module and the NodeMCU V0.9
In the end it only required a single multi-part rule to get the 20 minutes ON followed by 60 minutes of OFF. And it comes back for a re-boot/or power cycle controlling properly.



 rule1
   on system#boot do backlog ruletimer1 1800; power1 1 endon
   on rules#timer=1 do backlog ruletimer2 3600; power1 0 endon
   on rules#timer=2 do backlog ruletimer1 1800; power1 1 endon




A 3D-printed enclosure

I think the ESP needs to be outside the metal enclosure of the heater so it needs a protective case. I printed one with my Ender3 Pro.
The Tasmota WiFi interface on my phone
With the stock interface the fan can be turned ON or OFF.

The details, if you are interested:


I downloaded and installed tasmota from:

   https://github.com/arendst/Tasmota/releases/tag/v8.1.0
I then found that "on system#boot" does not work without mqtt and mDNS set, need patch
downloaded tasmota_8.1.0.10.bin from http://thehackbox.org/tasmota/

Then flashed it on a nodemcu V0.9 board with:

   esptool.py --port /dev/ttyUSB0  write_flash -fs 1MB -fm dout 0x0 tasmota.bin

The dual relay module on D2. (I don't need the second relay, but it is what was on hand.)



Nodemcu   Relay
5V --     VCC
GND  --   GND
D2   --   IN1
jumper to JD-VCC-VCC  not VCC-GND

connect WiFi on phone to 192.168.4.1 then set local WiFi configuration
reboot, net scan to find address. It may do mDNS.

config menu:  Generic(0)
 Save
D2 Relay1i(29)

Console:
rule on system#boot do backlog ruletimer1 1200; power1 1 endon on rules#timer=1 do backlog ruletimer2 3600; power1 0 endon on rules#timer=2 do backlog ruletimer1 1200; power1 1 endon
Save

Configure Other
  PurifierFan, purifierFan2
  Save

Console
  Rule1 1

Config- Save Config to-> /Config_tasmota_A450B3_4275_8.1.0.10.dmp

It has been working flawless for 3 days now. No sneezing or watery eyes since!

Thursday, April 4, 2019

Nodered, influxdb and Grafana

I had installed nodered to help monitor some of the systems on the boat and elsewhere some time ago. It has the ability to display some data, charts and plots with the extra "dashboard" module.
https://nodered.org/docs/getting-started/installation

I also installed mosquitto to collect data from the ESP devices and the OPis. I probably followed someone's notes, but I didn't seem to log it.
https://mosquitto.org/download/

It was OK for a while, but each time I restarted a display, it would start with no historical data. There was also no way to remove erroneous data. As I change things, plug in or forget to plug in things, I do get erroneous data points on occasion.

I tried sqlite/sqlite3 on op2e and croc for a while. It is like mysql, only a little simpler. I found an example flow for nodered and tried it for a while.
 https://www.youtube.com/watch?v=ccKspiI8FRw&feature=youtu.be
  https://flows.nodered.org/flow/36f2de38ed4bb62cf3a5e8fdc76d779e

Then I saw the youtube from Andreas https://www.youtube.com/watch?v=JdV4x925au0 and decided to try it.

It didn't take too long to get some data going into influxdb, but it did take some learning. The data had to be formatted just right to be inserted in a way that grafana could read it back.

For the simple case of a two values JSON string this is it. It did take a while fo make it this simple:


var tokens  = msg.topic.split("/");
msg.measurement   =tokens[1];       //get device  name from topic  level 3 /v1.6/devices/tokens[3]
var dest    = tokens[tokens.length-1];
inputjson   =JSON.parse(msg.payload);
msg.payload =inputjson;
return msg;
// End

For the more complex report for the disk space it took several days:


var tokens  = msg.topic.split("/");
sys = tokens[1];       

function extract(elem) {
    let extr = elem;// { fileSystem: "/home", percent: "96" }
   // node.warn(extr)
    var tag = {"host": sys, "filesystem": extr.fileSystem};
    msg.measurement = "Disk";
    msg.payload= [{"percent": extr.percent}, tag];
    node.send(msg);
    return extr;
    }
    
msg.payload.disk.forEach(extract);
// End

But it is working now.

The next hurdle was to get the data out into a graph with Grafana. A longer learning curve. And I'm not sure how to show it. Several windows for input all have to agree for the data to show up.

Overview


Just the battery monitor

Saturday, January 19, 2019

A Quick Look at RFID

Back in 2002, I was working a short contract in Seattle, just as the company was notified by Walmart that they must implement RFID on ALL of their products or no longer be eligible to sell through them. I dreamed of starting a consulting company specializing in implementing RFID, but then I realized I'd rather be retired and sailing in warm waters.

Just for kicks I ordered this RFID kit to evaluate, "MFRC-522 RC522 RFID RF IC Card Sensor Module". I would post a link, but I bought it in Chinese via Google Translate. It was only $2.63 so I couldn't pass it up.

I tested it on a Wemos D1 Mini, ESP8266, my current CPU of choice. The Arduino IDE has a library for the  MFRC-522 from  https://github.com/miguelbalboa/rfid. It includes several examples. It is 3.3v and has a SPI interface plus a RST signal.

I tried several of the examples and the reader actually works! The blue tag needed to be less than 1cm to read, but the white card worked out to about 2.5cm.

Writing also worked. Both types of tags are identified as 1kilobhyte. I only wrote my name so I didn't test the limits.



MFRC-522 RC522 RFID Card Sensor Module

Tuesday, January 1, 2019

More Battery Monitor

It was still too hard to tell whether the new batteries were coming up to full charge, so while I waited, I added to the monitor. I already have a current shunt for the old "Heart/Cruising Designs" monitor and now the Xantrex LinkLite, so all I had to do was hook the ADS1115 differential input channels to it.

I added the current monitor with amp hour calculation and a status web page to the Batt_volt_mon. I re-factored the code using the tab capability of the Arduino IDE rev 1.8.8.

I also copied from a friend the idea to make each tab's code optionally included at compile time with #ifdef's. This makes it easier to debug.


  #define DO_ADS
  #ifdef DO_ADS
     #include "ads.h"
  #endif //DO_ADS
     ...
  #ifdef DO_ADS
     setup_ads();
  #endif // DO_ADS
     ...
  #ifdef DO_ADS
     if ( (last_ads + ads_time) < millis() ){
       last_ads = millis();
       loop_ads();
     }
  #endif //DO_ADS
     ...

 
And I uploaded the new code to my github.

Top of the board with the modules out to see the wires
The bottom of the board

And then I documented the connections in Fritzing.
The Fritzing layout

Tuesday, April 3, 2018

Boat "House-Battery Bank" Monitor

The batteries on my boat seem to be failing. I decided to monitor the voltage to see how it is doing. I have 8 each 6 volt golf-cart deep cycle batteries wired series-parallel to give 12volts with 880 Amp-hours. But 2 have a shorted cell and are disconnected.

They are usually charged by 4 each 150 watt solar panels connected to 2 each 30 amp MPPT solar controllers. Also sometimes large frame alternators on the main engine or the diesel powered watermaker.

Anyway, the monitor is a Wemos D1 Mini with an ADS1115 4 channel A to D to measure the battery voltage. The 12volts (11.9 to 14.4) is outside the normal range of the ASD1115 so there is a resistor voltage divider implemented as a trimpot to set the voltage below the max allowed.

Also there is a cheap 3.3v buck converter on the board.

Once a minute it measures the battery (supply) voltage and sends to to node-red via mosquitto MQTT. It also checks for an OTA update each cycle.

The code is available on my GitHub: https://github.com/svkatielee/ESP8266_Arduino_projects





Thursday, March 29, 2018

Capacity Testing 18650 LiPo

I made a battery powered ESP8266 IoT device and wanted to check the real capacity of my 18650 battery. All 18650s are not created equal and may not be labeled correcdt either.

This is the setup:
Discharge through USB tester to load
First and last discharge the battery through a USB tester that counts milliamp hours.

Charging setup
Charge the battery with a USB LiPo charge module through the USB tester and note the mA hours.

Note the handy adapter board, electronic load and USB monitor are  from Aliexpress. But came as a bundle that I can't find today.The USB monitor is an ATorch brand.
i5i6S-Type-c-Micro-usb-MiNi-port-adapter-board-converter-battery-electrical-test-adapter-board