Thursday, 14 May 2026

Using hosts mDns/Avahi for Docker images

I’ve been trying to run Docker containers at home with one specific requirement: they need to resolve .local hostnames via mDNS so I can avoid the headache of managing static IPs.

The catch is that many of the containers I use aren't mine. They are standard images from the community, and I didn't want to maintain my own forks or modify their internal configurations just to get networking to work. I wanted a way to make mDNS "just work" from the host side.

Since I’m not a "networking guy," this proved more difficult than I expected. I spent a few evenings asking AI for advice and manually punching in commands based on its suggestions, but that didn't go anywhere.

Enter Gemini CLI and --yolo

After a bit of frustration, I decided to eliminate the middleman (me) and let the AI work directly on the system. I spun up a fresh, empty VM, installed the Gemini CLI, and spec'd exactly what I wanted.

I asked the AI what permissions it needed to achieve the goal autonomously in --yolo mode, which turned out to be passwordless sudo access. I granted the privileges and let it rip. After a bit of processing, it produced a working solution that I could then safely apply to my actual host.

TASK.md

Task: Configure Docker for mDNS/Avahi Resolution

Objective

Configure the Linux VM so that Docker containers can resolve .local mDNS addresses (specifically roope.local) without modifying existing container images.

Steps

  1. Logging: Maintain mdns_setup_log.txt with all actions, including failures.
  2. Host Setup:
    • Install/Ensure avahi-daemon and systemd-resolved are active.
    • Configure systemd-resolved to act as a bridge for mDNS to standard DNS.
  3. Docker Setup:
    • Identify Docker bridge IP (docker0).
    • Update /etc/docker/daemon.json to use the host’s bridge IP as the DNS server.
  4. Validation:
    • Verify roope.local resolution from an unmodified alpine container.
    • Verify connectivity via ping.
  5. Output: Write the successful configuration steps to SOLUTIONS.md.

Required Permissions

  • Sudo access (NOPASSWD) for system configuration.
  • Docker CLI access.
  • Workspace write access.

 SOLUTION.md

Solutions: Docker mDNS/Avahi Resolution

To enable Docker containers to resolve .local mDNS addresses without modifying images, the following steps were taken:

1. Configure systemd-resolved

A drop-in configuration was created to enable mDNS support and allow the stub listener to respond on the Docker bridge IP.

File: /etc/systemd/resolved.conf.d/mdns.conf

[Resolve]
MulticastDNS=yes
DNSStubListenerExtra=172.17.0.1

2. Enable mDNS on Network Interfaces

mDNS was enabled on the main network interface (ens18) to allow systemd-resolved to send/receive mDNS packets.

File: /etc/systemd/network/10-netplan-ens18.network.d/override.conf

[Network]
MulticastDNS=yes

3. Configure Docker

Docker was configured to use the host’s systemd-resolved stub listener (on the bridge IP) as the default DNS server for containers.

File: /etc/docker/daemon.json

{
  "dns": ["172.17.0.1"]
}

4. Services Restarted

The following services were restarted to apply changes:

sudo systemctl restart systemd-networkd
sudo systemctl restart systemd-resolved
sudo systemctl restart docker

5. Validation

Resolution was verified from an unmodified alpine container:

sudo docker run --rm alpine ping -c 1 roope.local

Output:

PING roope.local (192.168.0.106): 56 data bytes
64 bytes from 192.168.0.106: seq=0 ttl=63 time=0.714 ms

A Note on Security

I can't stress this enough: do not run AI in a production environment, especially with root privileges and --yolo mode enabled. Don't even do it on your primary development machine.

By using a throwaway VM, the risks were zero. If the AI decided to rm -rf / or wipe the partition, I'd just revert to a snapshot and try again. The absolute worst it could do was try to flood my LAN, which is a much smaller headache than a deleted home directory.


Thursday, 11 June 2020

Wooden handle for Rok espresso machine

The handle for our Rok espresso machine started to crack, decided it was too much work to find out how to order a new one, better make one myself. There was some apple tree that seemed like good choice.


Finished the handle with some oilwax, only one coat. Might put a few coats more in the future, we'll see how it holds.



Wednesday, 11 December 2019

Kona Ute head tube attached front rack

I bought a Kona Ute this fall, I like it, but we have two kids and they take all the space in the back so I needed some kind of front rack. I had previously had a front rack that attached to the front fork but found it cumbersome as it added to the mass that had to be turned when steering. So I wanted a rack that would attached to the frame. After some digging I couldn't find one, so I decided I would make one myself.

Kona Ute doesn't really have any good place for attaching a front rack to the frame, so I decided to bolt it to the head tube with two u-bolts. Luckily I had the old fork mounted rack still, so I only needed to build something to hold it in place. And the old rack was aluminium so it weights less.

Didn't take any pictures while building it, but it was just basically cutting some pieces and then welding them together.




Finished rack, color was chosen by my daughter:)


Saturday, 10 March 2018

Solar heat, update.

Some points I noticed while my solar heat system was installed last spring.

The glass cracked in couple of days, most likely the window frame was too tight. It was probably loose enough for normal use but in my use it heated to over 50 degrees and I'm guessing that was too much. Next time I'll make a new frame and make sure the glass is really loose in there.

I'm measuring the small solar panel wrong, I should be measuring amps and not voltage. Needs to be fixed sometime in the future.

ESP8266 real time clock is very inaccurate. I fixed this by ignoring the time sent and using the receiving servers time.

There's not enough error handling in my code and sometimes it crashes, most likely it's in the MQTT or NTP part, network trouble probably.

Using just convection didn't give that much heat so I added a fan. Currently it starts the fan when heated temperature is 20 degrees above inside temperature, when heated temperature is less than 10 degrees above room temperature then fan speed is decreased.

I used a standard 120 mm computer case fan I had lying around. "Case" for the fan was fabricobbeled from plastic cellular board I had salvaged from trash.


Here's an example of a sunny day, blue is outside temp (north side of the house), red is bottom of the collector, yellow is heated air and green is inside of our garage. Magenta is the "speed" of the fan, it's actually 10 bit pwm value of the ESP8266, as the fan doesn't have a pin for measuring speed, but it gives some idea on how fast the fan is running.

Updated source and Fritzing scheman can be found on github. https://github.com/mika-koivusaari/solar_air_heat_controller

Friday, 5 May 2017

Weather page

I've had a weather station at our summer house for some time now, but I never got around to publishing the the data. Now I had some time and made a Spring Boot application to show the data.

Station consists of 1-Wire sensors from Hobby-Boards. Temperature, barometer, wind speed and direction and rain sensors. I'll probably add a relative humidity sensor sometime so I can calculate the heat index also, currently only wind chill is calculated.

Since the weather station is located at our summer house with a somewhat flaky internet connection I can't just directly save data to my home servers database. I first save it locally and then replicate it home by reading MySQL's binary log. https://github.com/mika-koivusaari/replicate_mysql_postgresql Machines are connected with an SSH tunnel, I use autossh to make sure the tunnel is always open.

Weather page is https://weather.khyron.dy.fi/weather (in finnish), and code in https://github.com/mika-koivusaari/weather.

Friday, 17 March 2017

Solar heat

Our garage currently has no heating, sometimes when it's cold for a long time I put a electric heater there to make sure it doesn't go below freezing. For some time now I have thought about making a solar heater there and now I had some time to do it. One of the outside walls faces south and there is already an air intake, so that's a good starting point. I decided to only heat the incoming air and not make a full blown solar heat system with water circulation, it's cheaper and also I like to start small.

Collector

A house near us had it's windows replaced so I got one of the old ones for free. It was about the right size which reduced the work needed. Basically it's just a wooden box with polyurethane insulation I found in a dumpster, with the window put in front. Just behind the window is a tin foil paper with the paper side painted black and facing the window and sun. That way space where air heats and comes inside is covered with aluminium and there is no paint that might give out some fumes when heated. I ran out of paint so the collector isn't painted as black as it should, I'll probably paint it better in the summer as I have to take it out anyway so our garage wont heat too much. But I thought it would be good to get it installed and making heat, I can make it better later when I have some more data on how it works.

Controller

The controller needs foremost to control the flap on the air intake, because there are usually no people in the garage there is no need to get fresh air all the time, so the flap can be closed when there is no heat coming. Generally when air is hotter inside the collector we open the flap more, and when it's colder we close the flap some more. For operation there's only need for two temperature sensors, heated air and inside air, but I also want to monitor cold air coming to the collector so I have three sensors. That way I can monitor how much air heats and whats the temperature difference between north and south sides of our house. There is no fan, air is only moved by convection.

I also had a small solar cell from a Ikea garden lamp, which I added to get some reference to compare to when I make changes to the collector or controller. I put some resistors and diodes as a load, and scaled the voltage to 0 - 1 volts with a voltage divider.

All the values, temperatures, solar cell voltage and servo position are sent out with MQTT and then logged to a database so I can monitor how it works. And when I make changes I can see if it was a good or bad change.

On the left the protoboard version, and on the right the final veroboard version. Power supply is just some generic psu I had lying around as I use two dc-dc converters to make the needed 5 (LCD and servo) and 3.3 (ESP8266 and DS18B20 sensors) volts.


Controller in it's "final" installation. After one day I lowered the position of the servo some. It only opened the flap a few centimeters, now it opens some more.



Source and fritzing files can be found in github https://github.com/mika-koivusaari/solar_air_heat_controller

Thursday, 26 January 2017

MQTT MySQL gateway

Previously I've made a couple of sensors that send data with MQTT. Of course that data should be stored in a database. Considering that I'm probably going to make more wireless sensors that send data for example from our heating system it's best to write a easily configurable MQTT to database gateway. This gateway should also be able to send new values from database to MQTT nodes for displaying, as some data is gathered in other ways and inserted directly to db, for example OWFS(1-wire) or homegrown pulse counters.

So the basic functionality would be:
  • Recieve data from MQTT, process and save it to MySQL
  • Follow MySQL binlog and send saved data to MQTT
For input I need to have a table that stores:
  • Subscribed topic.
  • How to get raw sensorid from topic, maybe regexp.
  • How to parse data from message.
  • Small script that processes the data so it's ready to store.
And a second table that's used to convert raw sensorid's to db sensorid's:
  • Rawid
  • Sensorid
For output I need a table that stores:
  • Sensorid
  • Topic to push data to
  • How to process data before sending
There are still some features to implement, like outputting data from db to MQTT, need to think how this should be done with some kind of plugin system, MySql will probably use binlog to read data, but other databases have other mechanisms.

There are depencies for Paho-MQTT clientpep3143daemon and SQLAlchemy. More detailed dependencies in requirements.txt

Code in GitHub https://github.com/mika-koivusaari/mqtt_db_gateway.

Tuesday, 17 January 2017

Wooden urn

We had a death in the family and I wanted to make an urn for the ashes, before they are scattered.

For material I used birch and heat treated birch. I wanted to make the sides at an angle, and I found a nice calculator for compound miter angles. Sides are only at a 5 degree angle so the bevel is almost 45 degrees. Before I sawed bevels I routed a slot for bottom with my old adjustable jig(in finnish).


For the 5 degree angle I made a jig and tilted the saw blade for bevel.






Top was glued from four pieces, and one piece in the bottom to hold it in place, and cut to size with bottom. Finished with wax.


Wednesday, 30 November 2016

Magic ice wand

Santa Claus delegated manufacturing of one magic ice wand for me. After looking through my junk pile I found:

  • Clear plastic sheet
  • Blue led + resistor
  • One 18650 cell
  • Metal pipe
  • Push button
In addition I had to order one cell 18650 charger module with micro usb input.

Metal pipe functions as the handle, and plastic sheet as the ice part. I had to glue three sheets together with super glue to get the right thickness. Then I just soldered all together, tested it and added some hot glue and tape. Plastic was formed to icicle with a belt sander.


Metal pipe was painted pink and then I put everything together with hot glue.




Friday, 28 October 2016

Wifi temperature sensor

I have need for some temperature sensors where I'm too lazy install cables or the need is only for a short while. I also wanted to try micropython on ESP8266, so why not combine the two.

Installing micropython on ESP8266 is pretty simple, but somewhat time consuming the first time. Micropythons ESP8266 has good build instructions. Same goes goes for the needed esp open sdk. Building the esp-open-sdk takes pretty long time, but you don't have to update it that often.

What I want to do is have the eps8266 measure temperatures once a minute and then send the values with MQTT. Because I'm using DS18b20 sensors and they have a unique address I can just add that to the MQTT topic, something like /house/temperatures/1wire/285cb4ce0100009a and then have time and value in the message.

Micropython has a separate library repository that has MQTT library, but trying to just import that on ESP8266 gives an error and it seems that error is because there is not enough ram to compile to source, so the only way to use it is to precompile it by copying it to modules directory before building the firmware. That way it gets precompiled and you can use just like any other python module.

I'm thinking of sending the time in the message along with the value, for that I need to keep somewhat accurate time on the ESP8266.  I wrote a little script to see how accurate the rtc was, and it drifted about ten minutes in five hours, so I definitely should check the time every time I wake up from deep sleep. Script can be found here https://gist.github.com/mika-koivusaari/90febd8a101412bf0e5c71d9c736e855

Fritzing drawing of the connections. There isn't much stuff so I just soldered it all on the board. Sensors, power and battery monitor leads are of course with connectors.  I actually used a 18650 cell but didn't have a Fritzing part for that. I also used a dc - dc converter instead of a linear regulator.


Finished product, held together with heat shrink tube and hot glue:)




Code is pretty simple.

  • Wake up
  • Check if stop pin is down
  • Make measuments (only temperature and battery voltage at this time)
  • Wait for wifi connection
  • Connect to MQTT broker
  • Send values
  • Go to deep sleep

Code and Fritzing files can be found in https://github.com/mika-koivusaari/remote_sensor.

There's probably some bugs still that I have to sort out. But for future I might add some different sensors, for example humidity. Only send measured data every x minutes and store it between sends, to conserve battery. Maybe think some more about MQTT topics so they would be logical and extendable. Some more configuration options, and a local ntp server.

Next I should probably code a MySql - MQTT gateway so I can store those readings:)

Sunday, 23 October 2016

Trying C# and Visual Studio

I have never really worked with Microsofts development tools so I wanted to try. Visual Studio has a free community version that suits this purpose.

After a bit of thinking I thought I could make a RPN calculator, a simple program but I can still get some complexity there for fun.

Some points I want to try:

  • Operators as classes, just some basic oo-programming
  • Basic operators built-in, some operators loaded dynamically from dll
  • Unit testing
  • Refactoring
Dynamic loading of classes seems pretty simple, you just get the reference to Assembly (e.g. exe or dll) and then just look filter those classes that you are interested. getOperatorsFromAssembly function in Program.cs does the heavy lifting and is called from initOperators. Currently the only dll name is hardcoded, and a better solution would be to put all dll's in some directory and just load all of them, but I most likely won't do that.

Unit testing, Visual Studio can create test class stubs for a specific class, which is nice. Running tests is simple.

Basic refactoring, renaming and moving blocks of code to functions is straightforward.

Results can be found in github https://github.com/mika-koivusaari/rpn_calculator.

Monday, 19 September 2016

Measuring battery voltage with ESP8266

If you run IoT devices on batteries then it would be nice to know how much capacity is left on the battery, so you can change it before the device dies. Easiest way to do this is measuring battery voltage. Esp8266 has adc, but it's only from zero to one volt. The correct way would probably be to use Non-Inverting Op-Amp Level Shifter, but that would require many components and negative voltage. Easier approach is to just use voltage divider and just get the maximum voltage to acceptable range.

Using a calculator we get resistor values of 120kOhm and 39kOhm for getting 4.1 volts to 1 volt. For a low voltage of 3 volts these resistors would give 0.736 volts. So we are using 0.264 of esp8266 adc range of 0 - 1 volts. Adc is 10 bits so we have 0.264*1024=270 different values, even with some noise that should be enough for our purpose.



I made a small lua script that reads adc every minute and then posts the result with mqtt. Then used mosquitto_sub from Mosquitto to subscribe to that topic and log the messages.
mosquitto_sub -h roope.local -t /esp/battery | while read line; do echo -n $(date -Ins); echo -e "\t$line"; done | tee esp_battery.log Where roope.local is the mqtt broker machine.

Measurements and calculations can be found here https://docs.google.com/spreadsheets/d/1t18V1jrTRbj8nI5lrpctb8Fs9KzmpQ9O05dR5AeF37k/edit?usp=sharing. Esp_battery tab has raw data and formula has cleaned up data and formula.

I used google sheets linest function to calculate a function to get voltage from adc values, voltage=0.003539154715*adc+0.3756228338.

adcvoltage
10003.914777549
9003.560862077
8003.206946606
7002.853031134
6002.499115663

One problem for voltage divider is that it uses some power all the time. I should probably check how much that is, and if it considerably affects how long the battery will last. But for my next battery powered project, it will most likely report battery status also.


Thursday, 8 September 2016

You have mail 2

After having done the hardware for checking mail I had to make some kind of user interface to show that data. I had previously used an old IPhone to display temperature and power usage, so it was an easy choice to continue using it.

Previously I had just used a simple php script to fetch and display data, now I wanted to try python and Flask. I used a tutorial found here to get started.

Code is pretty simple, temperature and electricity usage is fetched every time from database, but this page is usually only open on the extra phone that displays this data so there shouldn't be any reason to cache that data. That data is also updated to database every minute so it should be refreshed every time. Mail status is received over mqtt and it's sent only when it changes so it has to be cached.


I also made a couple of changes to the hardware/firmware section, for the firmware I set the retain flag in the mqtt message so that when clients connect they get the last know value of mail. For the hardware I added a bigger antenna because I have some trouble with the wifi reception. Reception is still not as good as I would like, I have to think about it. Maybe second wifi ap, I'm also thinking if I should build a separate network for IoT-devices, currently there is only one wifi device, but that could easily change. I also changed the psu to one that outputs more current and has a lower quiescent current as I thought that the wifi problem might be because the ESP8266 is not getting enough current to transmit, but that didn't solve the problem. Before I had a cheap chinese buck/boost converter, and now I have https://www.pololu.com/product/2830 which can ouput more current, but is only a buck converter and needs at least 4 volts to output 3.3 volts. So I had to replace the three aaa batteries with four aa batteries to get enough voltage.

Also there is a problem with the mailbox itself:) It let's sunlight through somewhere and that's enough so we can't see if the led is on or not. I'll have to think how to put some seals there.

Future improvements

Hardware
  • Monitor battery state.
  • Don't turn radio on on wake up, only when we need to send. NodeMCU bug might prevent this currently.
Software
  • Move temperature and electricity to mqtt also.
  • Add today's forecast.

Wednesday, 31 August 2016

Fixing the apple press

After almost two falls our apple press broke, threads on it wheren't that good to begin with. The rod was ok but the nut had too weak threads. First I tried to find a suitable replacement nut but the threads where some weird size, probably imperial, so I had to change the rod too.



I used a 20 mm trapezoidal thread.


After fixing it works again.

Wednesday, 24 August 2016

Making apple juice

Fall, apples are getting ripe. Time make some juice.

We have several apple trees, and we know that if we just freeze slices we probably wont use them. But we do drink juice. We have tried juicers, but they tend to be meant for smaller scale, few liters maybe. Then I came across Matthias Wandel's homepage and his apple cider making page https://woodgears.ca/cider/. I copied the design somewhat and came up with this.


It's current in prototype stage, I want to make a bigger place to put the apples, preferably so large that I can just pour a whole moving box of apples there and let it crunch away. Also a better stand would be nice. The vfd in the back is just to test different speeds, I intend to replace that motor with something a bit smaller and one phase. Video of the crusher can be found here https://youtu.be/YjaJNmqus-Y

I haven't had time to build a press so I'm forced to use this store bought. It does it's job but could be better.

Today i harvested two trees, about four moving boxes full of apples, 30 liters of juice.

update: Second time, about 75 kg of apples gives about 25 litres of juice.

Tuesday, 9 August 2016

You have mail, power usage 2

Still no luck, batteries died over the weekend.

One of my thoughts was that if something goes wrong, for example we don't get wifi connection, then the device just sits there sucking power. So i added a timer just after we wake up that waits for 10 seconds and then goes to sleep, 10 seconds should be plenty time to get a connection and send data.

Also added was error handling to wifi and mqtt connections, if we don't get a connection we go to sleep and try again.

I also added a feature that we only send messages when state changes, and we only wake up the modem when we need to send something. For this I needed a new firmware that has rtcmem module. But the master had changed SDK version and I couldn't get the new firmware to work. I tried erasing (http://nodemcu.readthedocs.io/en/latest/en/flash/#upgrading-firmware) flash but still couldn't get it to work. I had to get the excellent Nodemcu-build docker image and use it to build a previous version. Which worked fine. I tried using the lowest power option in deep sleep, but there seems to be some problem with it, and I couldn't get it to work https://github.com/nodemcu/nodemcu-firmware/issues/1225.

On thing that also was on my mind was the really small antenna that came with the Esp-201 modules. Most likely a better antenna would give less trouble. I had some old adsl-modems laying around that had built in wifi with external antennas. I salvaged an antenna from one of them, and now I get better reception.


Thursday, 4 August 2016

You have mail, power usage.

After a less than 24 hours my mail sensors died. Batteries where around 1 volt, so it had drained them pretty quickly, something had to be done.

First I started to measure how many mA my circuit uses. But I was faced with a continually resetting Esp8266. At first I thought it had somehow messed the program in it's flash because of low voltage situation, but after a while of debugging I got the idea to measure the voltage, and it turns out that when measuring mA my multimeter drops the voltage from 3.3 to 3.1, and that makes the Esp8266 go crazy. Then I moved amperage measuring before the dc-dc converter. After that the circuit worked fine. There is a nice article about this issue here http://www.eevblog.com/files/uCurrentArticle.pdf

The following amperage readings are before the dc to dc converter when I powered the circuit from usb at 5 volts. When Esp8266 was active the circuit drawed around 40 - 100 mA of current. In deep sleep it took about 8 mA, which was quite high. After a bit of googling I found that the power led was using significant amount of power, so I took it out. Power went down to 3.4 mA, which is still quite high. After some thinking I started looking at how much TSL257 draws current, and it was typical 1.9 mA and max 3.5 mA according to datasheet. After moving TSL257 power to gpio, so it's only on during mail check, deep sleep current is 0.5mA, which is pretty much all taken by the dc-dc converter. Which I can't do anything about, without buying a new converter, so I'll settle for this now. If aaa batteries are about 1000 mAh then they should last about 1000/0.5/24=83 days, so over two months. Which at least gives me some time to think what I will do.

Tuesday, 2 August 2016

You have mail

Have you ever wondered has the mail arrived yet? I got my ESP8266 some while ago and was wondering what to do with it. After a while I thought it would be perfect for checking if mail had arrived, and I mean the traditional physical kind with envelopes.

Hardware

I figured some kind of light gate would be good for detecting if there is something in the mailbox. At first I tried with ldr and some led's, but couldn't get it to work. Either it didn't notice the led or ambient light was enough. Probably if I had a different type of ldr with different resistance it could have worked, but I didn't. So I used a TSL257 that I had lying aroung, and it seems to do the trick.

On the hardware side everything is simple, TSL257 connected to input pin, and a led with a transistor connected on a output pin. Because Esp8266 can only output a maximum of 12mA on it's pins I put a transistor to drive the led, so I could drive it at a higher amperage. Fritzing ESP-201 module from https://github.com/ydonnelly/ESP8266_fritzing.



Since I use deep sleep between checks XPD has to be connected to reset pin(black wire). Resistors on top of the Esp-201 and the yellow wire are for normal boot mode, as the module doesn't have these ready.

If pin2 (gpio4) is pulled low then the normal check and sleep is not done, this is so you can update lua scripts without reflashing the whole thing.

For a power supply I use three aaa batteries in series and a step down converted to get the 3.3 volts that is needed.

Since the circuit was so tiny I didn't use a pcb but just soldered the components together. Wires going to top right are for led and wires going bottom left are for TSL257.



I used a ESP-201 module, because it has an external antenna, and it's small and cheap. Because it doesn't have a usb connector it also has slightly smaller power usage, but I have to use a separate usb to serial module for programming. At first I used cheap clone ordered from aliexpress, but kept getting errors when flashing. So I bought a different module from a local shop and it worker like a charm. Others have also had trouble with cheap usb to serial modules when flashing ESP8266 modules.

Here is the device installed. Installation is not permanent, so I can better debug or change something if need be. Also we will probably get a new mailbox soon. Which would be good because our current mailbox is made from plastic and it lets light in just enough that when sun is shining it interferes. I had to tape the inside to block sun light.



And here is the inside.


Software

For programming I wanted to use NodeMCU and lua. I wanted to see if a interpreted language would be good enough, and it also has mqtt support.

Script itself is pretty simple:

  1. wakeup
  2. check if we see light, if so then there is too much light -> error
  3. turn on led
  4. check if we see light, light -> no mail, no light -> mail
  5. send message
  6. sleep
Programming with NodeMCU is pretty straightforward. But because it's event driven there is a bit of extra work with callbacks for this kind of batch job.

Code can be found here https://github.com/mika-koivusaari/you_have_mail.

Future improvements

After deep sleep check mail status first, and only if it has changed start modem and send message. Not sure how much this would improve battery life, but if it seems too short then I'll try.

Report battery status. Esp8266 only has adc range from 0 to 1 volts, so I would need to scale the voltage from three aaa batteries to that. Need to look into that sometime, it would probably be useful for other projects too.

Look for mqtt broker with mDNS, NodeMCU doesn't current have a mDNS client, so this will have to wait for that.

Next I'll have to make some kind user interface so I can actually see when the mail arrives.

Wednesday, 6 July 2016

Comparing solar radiation shields

I have three temperature sensors with calibration data that I want to test with different solar radiation shields.


From the left, normal shield made from plastic plates, tube made from twinwall sheet used in advertisement plates, same kind of tube but with fan.

Sensors (DS18B20) are read with OWFS and a small python script that starts the conversion for all sensors, reads them and then sends them to a Google Sheet using gspread. For some reason simultaneous conversion doesn't work for me, I get cached values. So I changed the script to just read sensors one after the other. Reading is done every minute. Also writing to Google Sheets is really slow, especially when done cell by cell. So I moved writing to Sheets to a different script that is run once a day.

Currently data is flowing in nicely, but I forgot to check which sensor is in which shield, so I have to check that the next time I travel to where those sensors are.

Writing to Google sheets is really easy with gspread, I can definitely recommend it if you need to work with Google sheets.

Raw data can be found in this Google sheet.

Python script in https://github.com/mika-koivusaari/read_ds18b20_gspread

Thursday, 16 June 2016

Calibrating DS18B20 sensors to show the same

I have a weather station in our summer house. It currently has a radiation shield made from plastic plates for the thermometer. It's "common knowledge" that if you have more air flow through you sensors it reflects more accurately ambient temperature. So forced airflow with a fan would more likely be better.

I want to test how much better. For this I need thermometers that show exactly the same value in the same temperature. So I'm going to put three sensors in salt water that's heated to about 40 degrees Celsius and then let it cool down to about -20°. Reading sensor values every minute should give a reasonable calibration table.

Motor in the top is for circulating water so I get more accurate results. It's a bit ugly setup but I only plan on using this for one time so I didn't bother with anything fancy.



Or at least that was the plan. 40° -> 20° went well but after I put the whole thing in the freezer all the DS18B20 sensors stopped working. I'm guessing some moisture related problem. I took the setup out of the freezer and let it heat from about -3° that it had cooled to room temperature. I'm probably not going to leave the test running for the winter so that range should be enough.

I used screen to read the values from serial "screen -L /dev/ttyUSB1". As cat seems to stop when arduino takes it's time to boot.

Data is in a Google spreadsheet DS18B20 calibration data.

There are three sensors A, B and C. Here are their maximum differences, and average differences.
A-B A-C B-C
Max difference 0.4375 0.3125 0.2500
Avg difference 0.0537 0.0353 0.0433

I'm thinking that the differences are not that big and I shouldn't worry about them. And some of it is most likely because I put a different amount of hotglue to the sensors to shield them.

Code used can be found in github https://github.com/mika-koivusaari/read_all_ds18b20