Zambretti Forecaster

The Zambretti Forecaster is a weather forecasting tool in the form of a circular slide rule introduced in 1920.  It claims to accurately predict near-term weather based on barometric pressure, the trend in the pressure (rising, steady, or falling), and wind direction. It relies on the fundamental meteorology of pressure fronts. Watch any TV weather forecast and you will see high- and low-pressure areas prominently displayed on the map. The boundaries between pressure areas are strongly associated with wind and precipitation. Additionally, high-pressure is usually associated with fair weather while low-pressure is associated with cloudy, rainy, or snowy weather.

The are many interesting things about the Zambretti Forecaster. First, there was no Mr. or Ms. Zambretti, rather, it was a trade name used by Negretti and Zambra, a famous London instrument-making company from the mid-19th Century through 1999. Second, there was a modern reproduction on sale in the mid-aughts of the 21st Century though it does not appear to be currently available.

Kevin Scott, Ph. D. has reverse-engineered the modern reproduction in very fine work reported at http://drkfs.net/zambretti.htm. He derived an algorithm that is easily implemented in computer code.

Since the D1M-WX1 weather stations accurately monitor barometric pressure, it is easy to apply the Zambretti Forecaster technique to a ThingSpeak channel. My adaptation of Dr.  Scott’s algorithm is provided below as a snippet for a MatLab visualization. To see this in action, open https://thingspeak.com/channels/286120. The Zambretti Forecast is at the bottom of the Current Values display.

Next steps:

  1.  Consider including the rate of barometric change in the forecast.
  2. Track the Zambretti Forecast against weather service predictions.
  3. Publish a pdf with instructions for making your own Zambretti Forecaster.

MATLAB code snippet:

Sending APRS Analog Telemetry – The basics

The amateur radio Automatic Packet Reporting System (APRS) is typically used for position and weather reporting. It can also handle eight digital and five analog telemetry channels. The IoT Kits© solar-powered weather stations have four APRS analog telemetry channels for LiPo cell voltage, time awake, WiFi signal strength, and light intensity. Four digital channels are used for warning alarms: low cell voltage, low signal strength, and sensor failures.

Analog telemetry is transmitted as an 8-bit word, therefore, the analog signal must be mapped to a range of 0 to 255. A good example is the mapping of LiPo cell voltage. An obvious mapping strategy would be to map voltage from 0 to, say, to 5 Vdc. This would quantize the results in steps of about  20 mV (5 V / 255) but it is unnecessary to report voltages below about 3 V because the D1 Mini will stop working.  If we map the range of 2.5 V to 5 V we will cut the quantization step in half to 10 mV, twice the precision of the first approach.  The weather station measures the cell voltage, subtracts 2.5 and divides the result by 10 mV. Say the cell voltage is 4.2, the mapped value is (4.2 – 2.5) ÷ 0.010 = 170.

The telemetry receiver must reverse this process by multiplying the received byte value by 0.010 and adding 2.5 like this: (170 × 0.010) + 2.5 = 4.2 Volts.

How does the receiver know that it must perform this operation to interpret the voltage? Two approaches are possible: we can send the telemetry “blind” since WE know how to interpret it, or we can send instructions so that anyone can understand our telemetry. The IoT Kits weather stations use the second method by sending instructions every two hours so that APRS services such as aprs.fi can correctly plot our data.

It actually takes four messages to completely define the analog telemetry:

T – T is the APRS symbol for telemetry. It is followed by a three-digit sequence number. Earlier versions of the D1M-WX1 weather stations sent a sequence number from 000 to 999 derived from UNIX time obtained fron an NTP server. Current versions send a number from 000 to 255 stored in the ESP8266 RTC memory and incremented on each wake cycle.

PARM – Defines the name of the parameter. APRS limits the name to three to six characters depending on the particular channel. The weather station transmits Vcell, RSSI, Light, and time awake.

UNIT – Defines the units for each channel with the name limited to 3 to 6 characters:  Vdc, dBm, lux, sec.

EQNS – Each analog channel has a quadratic equation that tells listeners how to interpret the 8-bit value associated with each channel.

A quadratic equation is a polynomial of the second order. That means that it is a polynomial function in one or more variables in which the highest-degree term is of the second degree. APRS uses this quadratic equation to interpret the received telemetry data: a · x2 + b · x + c where x is the received byte value.

The EQNS message transmits a set of three coefficients for each analog channel: a, b, and c

For the Vcell channel, the EQNS message looks like this: 0, 0.01, 2.5 meaning a = 0, b = 0.01, and c = 2.5. The receiver understands this to mean Vcell = 0 · x2 + 0.01 · x + 2.5

Let’s try it with a byte value of 163 as shown in the received telemetry data following:

Vcell = 0 ·1632 + 0.01 · 122 + 2.5

Vcell = 0 + 1.63 + 2.5 = 4.13 Volts

This is exactly what we had planned! This is how engineering and applied mathematics work in the real world.

Here is a sample of telemetry definitions from a D1M-WX1 weather station:

2018-10-09 15:53:32 EDT: W4KRL-15>APRS,TCPIP*,qAC,T2DENMARK:T#144,163,078,013,080,,1111,Solar Power WX Station
2018-10-09 15:53:32 EDT: W4KRL-15>APRS,TCPIP*,qAC,T2DENMARK::W4KRL-15 :PARM.Vcell,RSSI,Light,Awake,,BME28,BH17,loV,loS
2018-10-09 15:53:32 EDT: W4KRL-15>APRS,TCPIP*,qAC,T2DENMARK::W4KRL-15 :UNIT.Vdc,dBm,lux,secs,,OK,OK,OK,OK
2018-10-09 15:53:32 EDT: W4KRL-15>APRS,TCPIP*,qAC,T2DENMARK::W4KRL-15 :EQNS.0,0.01,2.5,0,-1,0,1,0,0,0,0.1,0
2018-10-09 15:53:32 EDT: W4KRL-15>APRS,TCPIP*,qAC,T2DENMARK::W4KRL-15 :BITS.Solar Power WX Station

Temporary Station using DIY Solar Shield

It has rained since we arrived at Bethany Beach, Delaware for vacation so it has not been able to test how well the DIY solar radiation shield performs in sunlight. It is hung on a small twig of a tree in the backyard.

ThingSpeak feed: https://thingspeak.com/channels/430753

APRS Feed: https://aprs-fi/W4KRL-13

DIY Instrument Shield

An instrument shelter provides a flow of air around weather sensors while protecting them from direct sunlight and rain. Without a shield, the sun can heat the temperature sensor giving a false high-temperature reading.

Professional weather stations use a large louvered box called a Stevenson Screen that is built to specific dimensions for standardized weather measurements. Smaller plastic shields can cost $100 or more. My station uses an AcuRite Radiation Shield that sometimes sells for as little as $10. Making your own instrument shelter can be an easy and fun project that may cost less than $6.

These instructions will give you a general idea how to build a shield. You can easily adapt the design to the materials you can find. The basic item is a shallow dish with nearly vertical straight sides. Dishes made as plant saucers are an excellent choice. The dishes are stacked on top of each other separated by beads and held together by wire ties. It makes a surprisingly sturdy design.

Here are suggested items. Any reasonable substitute will work if you can’t find these exact items:
• Dotchi 4-in Clear Plastic Plant Saucer – Lowe’s #606062 – $0.34. Buy six and maybe a few spares.
• Valspar White Spray Paint – Lowe’s #282255 – $0.99.
• Nylon Wire Ties – 6 to 11-inches long – Dollar Tree $1.00 or Harbor Freight $2.00
• Plastic or wood craft beads of the “large hole” variety. The hole must be large enough to allow the wire tie to pass through – Dollar Tree or Michael’s

You need to have at least six small saucers with flat bottoms and steep shallow sides. Plant saucers of 4 to 6-inch inch (100 mm – 150 mm) diameter work well. They are very thin so larger saucers are not strong enough. Paint them white with spray paint inside and out.

After the paint is dry, cut a hole in the flat bottom of five of the saucers leaving a ring at least 1/4-inch (6 mm) wide. The sixth uncut saucer will be the top of the shield. The holes should be a little larger than the width of the weather station printed circuit board, say 1.75-inches (45 mm). Cut three small slots wide enough to pass the tail of a wire tie in the flat bottom ring of each saucer. The slots must all line up. One way to do this is to make three equally spaced guide marks on the top saucer with a permanent marker. Place each of the other saucers over the top one and put marks in the same places. You can see the guide marks by holding them up to a light. Cut short slots at all the marks with a craft knife.

Look at how wire ties work: one side of the tail is smooth, the other side has ridges that engage with a tongue in the head of the tie.

Place the tail of a wire tie through each of the slots in the top saucer with the ridged side facing the center of the saucer hole. Put at least two beads over the tails of the wire ties coming out the other side of the saucer and thread them through the holes in the next saucer. Do this for each saucer.

You should now have a loose stack of saucers with three wire ties sticking out the bottom. Place a bead on each of the wire ties, then carefully press the head of another wire tie over each tail. You can tighten these up by hand to hold the stack firmly together. The tails of the new wire ties will cross more-or-less in the center of the bottom saucer. Cut three small slots in the side of the bottom saucer opposite from each wire tie. You can gently pry up the tails and insert the LiPo cell and weather station PCB into the hole with the solar cell outside. Pass the tails through the slots to secure the weather station in the shield.

Mounting the station is up to you. One possibility is to pass wire tie tails through the heads in the top of the shield and fasten them to some convenient bracket. For a few dollars more, buy a set of magnetic hooks like the ones Harbor Freight sells as item # 98502. Before you put your station inside the shield, drop a 1-1/2-inch (40 mm) steel (not stainless) washer into the shield. Place the magnetic hook on the other side so that it attracts the washer.

Solar Radiation Shield under test

The D1M-WX1 and D1S-WX1 solar-powered weather stations heat up in direct sunlight giving an incorrectly high-temperature reading. Early results from testing an Acurite solar radiation shield are very good.

The shield is available from several online vendors. Check around for a good price as the same item sells for $10 to $60 from different vendors.

https://www.acurite.com/solar-radiation-shield.html

I inserted a D1S shield-type station into the Acurite product and hot-melt glued the solar panel to the side of the solar shield. The shield comes apart by carefully prying small plastic tabs between each layer. This makes it easy to run wires into the shield.

On sunny days, the unshielded sensor heats up by more than 20ºC (36ºF) compared to the sensor in the AcuRite shield.

Since product availability is problematic, I am going to look into the possibility of building a DIY solar shield with dollar store components.

Power supply measurements

Most electronic projects operate on low voltage direct current. This is often provided by a USB connection or a battery. There are several possibilities to power a project from the 120 Vac power line. A common way is to use a wall adapter (wall wart) and feed low voltage direct current to your project through a power connector. A good feature of this approach is that the project enclosure is smaller because it does not need to house a power supply.

If you have a project that controls line power, like a Wi-Fi controlled receptacle, it is more convenient to incorporate the power supply in the project enclosure so that you do not need to connect to both the power line and a wall adapter. The solution is to include the guts of a wall adapter into the project enclosure.

Rather than taking apart a wall adapter, you can buy a phone charger kit from eBay vendors. Try searching for “diy training phone charger kit”.

According to the eBay listings, the specification is 5 Vdc at 350 mA to 500 mA with an input of 100-220 V 50//60Hz 0.3 A. This would be adequate for many Arduino and ESP8266 projects, sadly, the supply can barely meet 170 mA.

Next step is to modify the circuit to see if the output can be raised. Short out R7 and play around with R2, R3, and C2.

Di Mini (ESP8266) Wi-Fi Status Codes

The ESP8266 using the Arduino Core reports Wi-Fi status with the WiFi.status() function. The D1M-WX1 Weather Station attempts to connect to Wi-Fi every 250 milliseconds until the “Connect” status is found. If this does not happen after 15 attempts, it prints the status to the Serial Monitor.

Normally, the LED on the ESP8266 flashes five or six times until the connection is made. The LED will be dark during the six or seven seconds it takes to post the weather data on the Internet.  It will flash three times before the station goes to sleep for 10 minutes. The code is in the logonToRouter() function of the weather station sketches.

If a Wi-Fi connection can not be made, the LED will flash 16 times and the exit code will appear on the Serial Monitor. The status codes are:

ESP8266 WiFi Result Codes

CodeMeaningDescription
1No SSID AvailableUnit is too far from the Wi-Fi access point, the SSID and/or password is incorrect, or the SSID is for a 5GHz-band access point.
2Scan CompletedScanning for available networks is completed.
3ConnectedSuccess
4Connection FailedThe opposite of success.
5Connection Lost
6Disconnected
255No ShieldUsed for compatibility with the Arduino WiFi Shield - not relevant to the ESP8266.

Reference: https://www.arduino.cc/en/Reference/WiFiStatus

Sleep Mode for the Wemos D1 Mini

The key to using solar power in an Internet of Things project is to put the microcontroller unit into sleep modeafter the sensors are read and the data posted to your IoT server. The NodeMCU and the Wemos D1 WiFi, a larger profile that mimics the Arduino UNO form, reliably woke from deep sleep. So far, the Adafruit HUZZAH fails to wake after 20 or 30 sleep cycles. I’m still working on the HUZZAH but the letter carrier just brought a package with three Wemos D1 Mini ESP8266 devkits and an OLED display shield.

Would the D1 Mini also work well with deep sleep? Answering that question had to wait until I checked out the OLED display.

The D1 Mini devkits are supplied with both male and female headers. You must install the female headers if you want to use the OLED shield as a plug-in unit. Make sure you install the headers on the correct side so that the shields will stack with correct connections.

Both Adafruit and Sparkfun have Arduino libraries for this display. The Sparkfun library loaded easily and the examples brought up bright, clear images.

The next step was to make a DIY shield to mount BMP180 and HT21D sensors. The BMP180 measures atmospheric pressure and temperature. The HTU21D measures temperature and humidity. [I will post some photos in a week.] It makes a nice compact little cube with the sensor shield stacked between the D1 Mini and the OLED.

Having proven the OLED display, I removed it and set about to put the D1 Mini and sensor shield into deep sleep. There were some problems doing this. When the ESP8266 wakes up, it needs to be reset to restart execution of the firmware. The ESP8266 provides a signal on pin D0 to do this so D0 must be connected to the Reset pin. However, this connection sometimes interferes with putting the ESP8288 into programming mode and must be opened to reprogram the chip.

I also ran into some problems when power was removed while the chip was in deep sleep.

After getting the chip to sleep and wake up I ran some current tests. The D1 Mini drew an average of 80mA when awake and 2.4mA when asleep. The D1 Mini has a small red LED that lights when the board is powered. I pulled the LED off the board with a pair of pliers. That dropped the sleep current down to 70µA.  This makes the D1 Mini look like a very good choice for solar powered IoT projects.

External sensors for weather station

Recently the local Institute of Electrical and Electronic Engineers (IEEE) held two “hands-on” sessions to build an Internet of Things (IoT) weather station. We built it on a breadboard so that the attendees would not have to solder wires. Several of the participants have kept their stations on-line and two have placed the unit outdoors.

Finding a suitable outdoor enclosure for the sensors is difficult. There are several available for relatively large sensors with costs from $30 to hundreds. Fortunately, a scrounging mission to Walmart turned up a nice little box for 88¢!

The box is 88 x 60 x 50mm (3.25 x 2.38 x 2.00-in). The box is transparent and has a lid the fits over the sides of the box. There is some play between the lid and the box so it allows some air movement. This can be “enhanced” by drilling four 6mm (1/4-inch) holes in the bottom of the box.

The box neatly holds a BME280 barometric pressure/temperature/humidity sensor and a BH1750 light intensity sensor. A piece of stripboard mounts the sensor breakout boards. Since the sensors are I2C devices they need four wires (two I2C and 2 power) to connect to the “control unit”. I cut the ends off a flat USB cable from the dollar store. It requires a lot of careful patience to solder the very small wires to the stripboard. I am looking for a better method.

My box is mounted to a second-floor window frame with clear packing tape. The window is above a small shingled roof. This is not an ideal location because solar heating of the roof probably affects the temperature reading. In practice, the temperature accurately tracks the local WeatherBug station reading.

The unit has been outside since 10 November 2016. It has been through several rain storms with no problems.

Outdoor Unit in rain

Solar Power Supply

A solar power supply would be a really neat addition to any Internet of Things project. The ultimate goal would be to have a self-sufficient IoT device that could be remotely reprogrammed with the Over The Air (OTA) feature.

A key to using solar power is to reduce the average power requirement of the IoT device. The ESP8266 can be put in several levels of sleep but dev kits (development kits) like the NodeMCU have other power hungry support devices that swamp out the ESP8266 power draw. The two main consumers are the voltage regulator and the USB converter chip. In deep sleep mode, the ESP8266 draws about 70μA while the total draw of the NodeMCU is about 15mA. Several people have “fixed” this issue by removing the regulator and cutting traces to the USB chip. Removing the regulator is easy, cutting traces on the USB is difficult. It was even more difficult in my case because the particular NodeMCU I was attempting to modify uses the CH340G chip rather than the CP2102. Theoretically, the same process of lifting the Vcc connection should work. For the CH340G, this is pin 16, however, I found there is no direct connection between pin 16 and 3.3V. Not having a schematic, I decided to look for other options.

I had hoped that the Adafruit HUZZAH is a good choice for sleep mode experiments. After days of experimentation, the HUZZAH fails to wake after about 20 or 30 sleep cycles. Others have experienced the same problem and offered solutions. To date, none have worked for me.

Using the exact same software, the Wemos D1 WiFi has worked perfectly. Unfortunately, the D1 has similar parasitic loads like the NodeMCU so is not a good choice for a solar-powered project. Since the same software fails on the HUZZAH there must be some hardware solution. I drew up the circuits for both dev kits with the objective of building the same circuit around the HUZZAH using external components.

Since the same software that works on the D1 fails on the HUZZAH, there must be some hardware problem. I drew up the circuits for both dev kits with the objective of building the same circuit around the HUZZAH using external components.

Schematic comparison of Wemos D1 WiFi and the Adafruit HUZZAH.

The suspiciously missing components from the D1 are circled in orange. The most significant are:

  • C11 – a 100nF capacitor from the Reset pin to ground. This value is suggested by Expressif. It probably provides some time delay on the wake-up pulse. Added this between GND and RST on the HUZZAH.
  • C10 – a 100nF bypass capacitor on Vcc. Probably not too important but easy to add between 3V and GND on the HUZZAH.
  • R13 – a 10K pull-up resistor on GPIO0. The HUZZAH has an LED in this line that may introduce too much voltage drop and leave GPIO0 in an indeterminate state. Added a 10K between 3V and #0 on the HUZZAH.
  • The logic circuit of Q1 and Q2 is driven by the DTR and RTS lines from the USB chip to automatically put the ESP8266 into programming mode. I do not think their omission from the HUZZAH is the problem. But I could be wrong!

Sadly, the HUZZAH still fails to come out of deep sleep after about 20 cycles of 120 second sleep duration.