MM Defender IOT Controller
I stupidly blew up the Mosquito Magnet Defender PIC controller, see MM Defender Controller. The only alternative was a new controller. I looked at Arduino boards, which have a robust environment community. However, I just discovered the Espressif Systems ESP8266 WIFI chip, which has very limited computing capacity, but WIFI connectivity! I purchased a couple of very cheap development boards, and programmed a new controller using the data below, and wired it into the board in place of the PIC controller. Today it is working, catching hundreds of hungry mosquitos in its first day of operation. Plus, I can check it and the combustion chamber temperature from my PC or phone. What more could I ask?
Actually, I could ask quite a lot more. For more information, see the MM blog. Here is the second revision schematic.
The $4 NodeMCU ESP-12E wireless development board provides greatly improved troubleshooting. Temperature is measured using the 12 bit ADC input buffered by a 220k/100k divider to give a 3.2v full scale input. R6 (20k) drops 3.3 volts so that an open thermistor TH201 yields about full scale. ThermLo connects to U301 D5 open drain that is switched on and off to add and remove TH201, yielding a voltage ratio to calculate its resistance then temperature.
The software implements an MQTT client that publishes its status 'topic' to an MQTT broker for viewing on a PC or phone app. It can also receive commands. A simple web page can also be implemented. WiFi configuration is done with the unit in access point mode so you can enter a WiFi SSID and password.
The development board has 2 rows of 15 pins on 100 mil centers to fit standard 100 mil sockets. I used a 15 pin socket for the right side, and a dual and single socket for the left side. Flexible stranded 6" color coded wires are soldered to the used pins. On the original controller board, the foil from the +5v rail was cut. The new rail is labeled +5C, which is powered by the +3.3v from the NodeMCU board. The lower voltage seems to work (power the LED, Q1 gas driver, and the two FETs for the fan and igniter). The foil from C4 was also cut. I removed the PIC because it was absolutely fried with no possibility of recovery. Alternately, I could have lifted and grounded the reset pin, to effectively remove it from the circuit. The wires to the NodeMCU are soldered onto components or vias where possible - the largish wires can easily rip up a thin foil trace on the controller. The wires should be glued down or potted to the PCB for greater stability (later).
The controller drives 5 outputs: switch LED, Gas, Fan, Igniter, and an new open drain output 'ThermLo.' It has a digital input to read the switch position. The analog input measures the voltage across the thermistor TH201 when the ThermLo output is low (drain to ground about 20 ohms). When ThermLo goes open drain (high impedance), it measures the +3.3v power supply voltage divided by the 20k resistor and the adc input. This ratio measurement technique is intended to compensate for variations in the +3.3v rail plus other temperature variations. Two more pins are used for I2C communication with an optional HTU21D temperature and humidity sensor board.
The software is three revisions removed from "Hello, World" quality, with improved error recovery and the like. From the start, it has been capable of starting the running the trap without unduly endangering life and limb. Currently, it connects to one of two open public MQTT broker servers: test.mosquitto.org on the /test/MMD/esp# topic, and broker.hivemq.com on the MMD/esp# topic, where the # wild card is some number or other identifier. The unit publishes internal temperature and state info once per second. For now, you can look at that using an MQTT client and tell if the trap is running or not. The broker server and topic may change to a private service at some point.
Version 3.0 MQTT Messages
The software sends a line of information about once per second.
- The first two numbers are temperature in Celsius followed by the (temperature change).
- The next numbers show the state # (1-7) : then approximate seconds in that state.
- The next five show the Fan, Igniter, and Gas outputs followed by the Switch position and last Error code.
- The next two numbers show the temperature and humidity according to the optional HTU21D sensor module.
- The following items are diagnostics:
- M is the available heap memory (in bytes)
- The numbers in parentheses are the ADC output with the thermistor in the circuit and out, followed by the calculated thermistor resistance.
- The B indicates connected to the MQTT server and web server queue timer, and V is the software version.
The chart plots the combustion temperature, case temperature, and state. You can click on the chart to get a bigger version.
Here are some v2.5 messages from that chart at interesting points:
At Jul 03 2018 at 21:27:44, the trap is off in the 7 Error state, then restarted into 2 Igniter:
Temp=29.9C (0.2) at 7:7677 F=0 I=0 G=0 S=1 E=7 T=28.5C H=78.7% M=12168 (909/1016:159912) B=1
Temp=30.1C (0.2) at 2:0 F=1 I=1 G=0 S=1 E=0 T=28.5C H=78.7% M=12160 (908/1016:158257) B=1
After 15 seconds, the trap enters 3 Start state:
Temp=29.9C (0.2) at 3:0 F=1 I=1 G=0 S=1 E=0 T=28.7C H=81.7% M=12168 (909/1016:159912) B=1
after 57 seconds, the temperature has risen 5 degrees:
Temp=35C (0.2) at 3:57 F=1 I=1 G=1 S=1 E=0 T=28.8C H=82.7% M=12160 (883/1014:126879) B=1
after 84 seconds, the temperature has risen to 40C:
Temp=40C (0.2) at 3:84 F=1 I=1 G=1 S=1 E=0 T=28.9C H=82.5% M=12160 (856/1014:101981) B=1
after 121 seconds, the temperature has risen to 50C, and enters state 4 Rise:
Temp=50.7C (0.8) at 3:121 F=1 I=1 G=1 S=1 E=0 T=29.2C H=81.5% M=12168 (787/1013:65549) B=1
Temp=50.4C (-0.3) at 4:0 F=1 I=1 G=1 S=1 E=0 T=29.2C H=81.4% M=12160 (785/1013:64809) B=1
after 2 seconds, the temperature is above 50C, and enters state 5 Steady:
Temp=51.4C (0.8) at 4:2 F=1 I=0 G=1 S=1 E=0 T=29.3C H=81.3% M=12160 (776/1011:62158) B=1
Temp=51.9C (0.5) at 5:1 F=1 I=0 G=1 S=1 E=0 T=29.3C H=81.2% M=12168 (774/1013:60960) B=1
after 43 seconds, the temperature has risen to 70C:
Temp=70.5C (0.7) at 5:43 F=1 I=0 G=1 S=1 E=0 T=29.9C H=78.7% M=12160 (619/1011:29724) B=1
after 99 seconds, the temperature has risen to 90C:
Temp=90.1C (0.5) at 5:99 F=1 I=0 G=1 S=1 E=0 T=31C H=74.4% M=12000 (452/1013:15166) B=1
after 137 seconds, the temperature has risen to 100C:
Temp=99.9C (-0.8) at 5:137 F=1 I=0 G=1 S=1 E=0 T=31.8C H=71.2% M=12168 (375/1014:11047) B=1
after 204 seconds, the temperature has risen to 110C:
Temp=110.9C (-0.8) at 5:204 F=1 I=0 G=1 S=1 E=0 T=33.3C H=66.5% M=12192 (297/1014:7797) B=1
after 308 seconds, the temperature has risen to 120C:
Temp=120C (0.2) at 5:308 F=1 I=0 G=1 S=1 E=0 T=35.2C H=58.8% M=12192 (245/1015:5989) B=1
The trap stays there for quite a while, then after 836 seconds, the temperature has risen to 130C:
Temp=130.1C (1.5) at 5:836 F=1 I=0 G=1 S=1 E=0 T=40.3C H=43.5% M=12192 (197/1012:4550) B=1
It holds this temperature until 1017 seconds, then increases:
Temp=130.4C (-1.9) at 5:1017 F=1 I=0 G=1 S=1 E=0 T=40.5C H=43.7% M=12168 (196/1015:4505) B=1
Temp=140.2C (0.3) at 5:1161 F=1 I=0 G=1 S=1 E=0 T=40.4C H=43.6% M=12192 (159/1015:3496) B=1
Temp=150.4C (-1.3) at 5:1205 F=1 I=0 G=1 S=1 E=0 T=40.4C H=43.7% M=12192 (128/1015:2716) B=1
Temp=160.3C (3) at 5:1541 F=1 I=0 G=1 S=1 E=0 T=40.2C H=44% M=12192 (97/1012:1995) B=1
It hits the peak of 166C and stays there for a long time:
Temp=166.2C (2.4) at 5:2080 F=1 I=0 G=1 S=1 E=0 T=40C H=44.3% M=12168 (85/1012:1726) B=1
Temp=165.7C (2.9) at 5:11872 F=1 I=0 G=1 S=1 E=0 T=38.8C H=41.8% M=12192 (86/1012:1748) B=1
Then for some reason, the temperature drops.
Temp=160.3C (-0.5) at 5:21691 F=1 I=0 G=1 S=1 E=0 T=36.4C H=39.7% M=12192 (97/1012:1995) B=1
Temp=124C (-1.4) at 5:21945 F=1 I=0 G=1 S=1 E=0 T=36C H=40.2% M=12328 (225/1015:5361) B=1
The system rebooted (why?). There is a 35 second gap between consecutive messages, and the state changes from 5 Steady to 1 Clear, which on version 2.5 software requires cooling down to 40C before restarting.
Temp=122.1C (1.1) at 5:27059 F=1 I=0 G=1 S=1 E=0 T=35.4C H=39.8% M=12368 (234/1013:5654) B=1 (at 1530695313.077)
Temp=120.9C (-0.4) at 1:19 F=1 I=0 G=0 S=1 E=0 T=35.4C H=38.9% M=13056 (240/1013:5844) B=1 (at 1530695348.373)
It took a while, but the trap has cooled and is restarting.
Temp=39.8C (-0.2) at 1:261 F=1 I=0 G=0 S=1 E=0 T=29.4C H=55% M=12376 (859/1016:102990) B=1
Temp=39.8C (0) at 2:3 F=1 I=1 G=0 S=1 E=0 T=29.4C H=55.1% M=12376 (860/1017:103110) B=1
Up to temperature and the two stable temperature levels:
Temp=112C (1.1) at 5:258 F=1 I=0 G=1 S=1 E=0 T=30.8C H=52.4% M=12360 (290/1013:7550) B=1
Temp=125.5C (-1.4) at 5:13895 F=1 I=0 G=1 S=1 E=0 T=41.4C H=32.1% M=12392 (218/1015:5149) B=1
Temp=156.3C (3.2) at 5:14276 F=1 I=0 G=1 S=1 E=0 T=41.9C H=26.9% M=12392 (105/1013:2177) B=1
An unexplained pause in the messaging.
Combustion has stopped (but the gas is still on). The system cools to under 50C, and enters state 7 Error:
Temp=155C (2.3) at 5:21921 F=1 I=0 G=1 S=1 E=0 T=44.2C H=19.2% M=12400 (108/1012:2249) B=1
Temp=100C (-0.9) at 5:22503 F=1 I=0 G=1 S=1 E=0 T=43C H=22.3% M=12400 (375/1016:11012) B=1
Temp=60C (-0.3) at 5:22628 F=1 I=0 G=1 S=1 E=0 T=41.7C H=21.4% M=12384 (713/1017:44149) B=1
Temp=50C (0) at 5:22716 F=1 I=0 G=1 S=1 E=0 T=40.6C H=23.6% M=12384 (793/1014:67543) B=1
Temp=40C (0.2) at 6:254 F=1 I=0 G=0 S=1 E=7 T=38.4C H=28.8% M=12392 (857/1015:102100) B=1
After 300 seconds of cooling, the fan shuts off and the light blinks rapidly:
Temp=38.9C (-0.4) at 6:297 F=1 I=0 G=0 S=1 E=7 T=38.3C H=28.3% M=12400 (865/1017:107121) B=1
Temp=39.3C (0.4) at 7:5 F=0 I=0 G=0 S=1 E=7 T=38.3C H=28.1% M=12392 (860/1014:105118) B=1
I have no explanation for the the observed temperature rise and return. Reading one of the patents for the Mosquito Magnet Liberty invention, the propane burn is direct combustion, not catalytic conversion. The catalyst is there only to remove carbon monoxide, a mosquito repellent. The converter assembly includes lengthwise passages to make the gas flow less turbulent for even burning, so that unburned propane, another repellent, is reduced. I don't understand any of this well enough.
The patent states that the Liberty checks for too-high temperature, and if this is reached, it turns off the gas and waits for the trap to cool, then restarts it. If this happens again, it enters a high temperature fault condition and stops.
For the rest of this discussion see MM blog.
This software is the second revision.
- The MQTT message deemphasizes the raw ADC voltages and thermistor resistance, moving it to the end, along with other "debug" information.
- If not connected to WiFi, the system operates in access point mode to display a WiFi configuration web page. No USB cable required.
- When connected to WiFi, a web page configures MQTT and re-configures WiFi. MQTT broker server, port, and topic, and optionally, user and password.
- The web page displays instructions for setting up the WiFi.
First revision notes:
- The igniter is on without the gas in state 2 to allow the igniter to get hot enough before the gas arrives. I am hoping to avoid the 'pop' explosion observed in the original unit.
- Issue: Like the previous controller, there is sometimes a pop that sounds like a small explosion when the gas finally starts combustion. I would like to eliminate that, perhaps by increasing the gas levels gradually until a rapid temperature rise.
- The software re-connects to the MQTT broker server if the connection is lost.
- It now responds to commands to change the state, for experimenting.
- Improve the control of the combustion process.
June 13, 2018
Last night, the trap would start then die as the internal temperature reached 130 C. It did this 3 times. The steady state was about 100-110 C, but initially the temperature climbs to about 150 C before it settles down. But the combustion stopped at 130 degrees, and it cooled all the way down to where the gas turned off and the fast blinking fault state entered. My guess is that the NodeMCU was getting too hot. I moved the board as far away from the combustion chamber as I could, and that worked. The whole system is marginal regarding heat and environmental conditions. We will see what happens during a thunderstorm. Again, my guess is that Q1 is losing drive and opening up, shutting off the gas at this temperature. I will have to instrument this to see what is happening. But now it is working, and the mosquitos are coming far and wide. Just keep going!
June 27, 2018
The trap has run for 2 weeks now. The trap shuts down when it gets too hot outside. My suspicion is that the gas solenoid transistor drive from R10 2k2 to 3.3v is insufficient to saturate Q1 and hold the valve open. The running temperature has ranged from 97 to over 110 degrees C. The NodeMCU controller has been moved to the back of the unit, away from the hot gas intake, to try to eliminate that as an issue. The controller continues to send out data even when the combustion fails. The chamber temperature reaches 130-150 degrees then it just falls until the trap shuts down at 50 C. To investigate this, I added a temperature and humidity sensor to the system. Initially, it will be internal near the NodeMCU board. After the system is debugged, perhaps it can measure the ambient conditions and automatically start and stop the unit when conditions warrant. The MQTT listing above has changed to support the new data.
The system displays its own web page, against the advice of NodeMCU gurus who advise keeping the system minimal. However, a nano web server that can display dynamic data and accept commands would be quite useful and perhaps entertaining. The web page it displays is not that simple see MM Defender NodeMCU Configuration Page. It even includes a silly mosquito background, that you can hide or fade. Anyway, it provides a method to configure the MQTT client. Because much of the logic is on the web page itself, the page can get fairly complicated and still not crash the NodeMCU.
July 4, 2018
After some rain that broke a drought, the trap caught an entire basket full of mosquitos (est ~10,000). They were waiting to eat me, but the trap got them first. This trap as many mosquitos as it has caught in the last 10 years. Updating the software, looking into chamber temperature rise and subsequent shutdown.
These have been moved from above and have been superseded by the information above. They are here for historical reasons.
Version 1.0 MQTT Messages
The software currently sends a line of information about once per second. Here are some messages separated by several minutes each:
The first two numbers are the adc output with the thermistor in the circuit and out. This ratio permits calculation of the thermistor resistance. The temperature in Celsius from a complex formula, followed by the (temperature change). The next numbers show the state # (1-7) : then approximate seconds in that state. The last five show the Fan, Igniter, and Gas outputs followed by the switch position and last error code.
temp = 471 / 1015 = 16298 = 88.6 C (-0.3) at 1:3 F=1 I=0 G=0 S=1 E=0 temp = 861 / 1018 = 103230 = 39.8 C (-0.2) at 1:394 F=1 I=0 G=0 S=1 E=0 temp = 859 / 1015 = 103650 = 39.7 C (-0.1) at 2:3 F=1 I=1 G=0 S=1 E=0 temp = 861 / 1015 = 105241 = 39.4 C (0.4) at 3:2 F=1 I=1 G=1 S=1 E=0 temp = 861 / 1015 = 105241 = 39.4 C (0.4) at 3:40 F=1 I=1 G=1 S=1 E=0 temp = 835 / 1018 = 85889 = 44.1 C (0.2) at 3:90 F=1 I=1 G=1 S=1 E=0 temp = 792 / 1015 = 66853 = 50.2 C (0.3) at 3:118 F=1 I=1 G=1 S=1 E=0 temp = 787 / 1015 = 64974 = 50.3 C (0.1) at 4:0 F=1 I=1 G=1 S=1 E=0 temp = 330 / 1017 = 9042 = 106 C (0.2) at 5:352 F=1 I=0 G=1 S=1 E=0 temp = 291 / 1016 = 7555 = 112 C (0.2) at 5:889 F=1 I=0 G=1 S=1 E=0 temp = 242 / 1016 = 5885 = 120.7 C (0.2) at 5:959 F=1 I=0 G=1 S=1 E=0 temp = 196 / 1016 = 4499 = 130.5 C (0.2) at 5:1019 F=1 I=0 G=1 S=1 E=0 temp = 159 / 1014 = 3501 = 140.1 C (1.9) at 5:1258 F=1 I=0 G=1 S=1 E=0 temp = 128 / 1014 = 2719 = 150.3 C (2.4) at 5:1554 F=1 I=0 G=1 S=1 E=0 temp = 127 / 1015 = 2692 = 150.7 C (0.4) at 5:1561 F=1 I=0 G=1 S=1 E=0 temp = 127 / 1014 = 2695 = 150.7 C (-0.4) at 5:1703 F=1 I=0 G=1 S=1 E=0 temp = 159 / 1014 = 3501 = 140.1 C (1) at 5:1741 F=1 I=0 G=1 S=1 E=0 temp = 198 / 1016 = 4556 = 130 C (-0.3) at 5:1776 F=1 I=0 G=1 S=1 E=0 temp = 242 / 1015 = 5893 = 120.6 C (0.9) at 5:1838 F=1 I=0 G=1 S=1 E=0 temp = 303 / 1016 = 7999 = 110 C (-0.2) at 5:2232 F=1 I=0 G=1 S=1 E=0 temp = 320 / 1016 = 8654 = 107.4 C (-0.7) at 5:8987 F=1 I=0 G=1 S=1 E=0 temp = 321 / 1016 = 8694 = 107.3 C (-0.6) at 5:11433 F=1 I=0 G=1 S=1 E=0
(Note: the MQTT message has changed to support new functionality. This topic will be updated.)
- In this trial, the trap was stopped to replace the revision 0 software with rev 1. It was still hot (88.6 C) when restarted. The current algorithm requires the trap to initially cool down (state 1) to an initial temperature well below the starting combustion temperature so that we can tell whether the gas is burning or not.
- At 394 seconds into state 1, the temperature has dropped to "cool enough," and the controller moves to state 2 - igniter, which is activated, and the fan power (and air flow) reduced.
- After 15 seconds, state 3 - gas on, is entered. The fan is returned to full power, and the gas is turned on.
- At 3:90, a significant temperature rise is noted. It takes 90 seconds, seemingly a long time.
- At 3:118, the temperature exceeds 50 C, which means it is getting hot, and the trap enters the state 4 - warming, then right away to state 5 - steady (although it is by no means steady, but it is likely to work). The switch light changes from blinking to solid.
- At 5:352, typical operating temperature (about 110 C) is reached. You would think that would be that, but no.
Temperature Rise and Return
- At 5:889, the trap temperature starts to climb. Ot reaches peak at 5:1554, stays there until 5:1703, then starts to decline
- at 5:2242, the trap temperature begins to stabilize at 110 C, slowly dropping to about 107 C over a period of time.
110 C is apparently the real steady state. 2242 seconds (37 minutes) is a long time after starting the trap. Perhaps the trap should send out a celebratory email, but who would be paying attention at this point? Life is too short. But, mosquitos make enjoyment of any life more difficult, so perhaps there is a question worth asking. The point is, you are not really sure the trap is working unless the temperature stabilizes, and this takes a quite long time. Oh, dear. What to do?
I have no explanation for the the observed temperature rise and return. I suppose the catalyst is heating up and ... what? If anyone can think of an explanation, please let us know.
For more information, see the MM blog.