Difference between revisions of "StofAnanas"

From RevSpace
Jump to navigation Jump to search
m (Usage)
(The concept)
(47 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
}}
 
}}
  
== The idea ==
+
== The concept ==
Show current airborne particulate matter concentration using a LED light in a lamp, inspired by http://stoflamp.nl
+
The stofananas/stoflama/pmlamp shows airborne particulate matter concentration from the nearest luftdaten citizen science measurement station as a colour on a LED lamp, inspired by http://stoflamp.nl
The data that the LED colour is based on is simply retrieved over WiFi from the luftdaten website.
+
The data that the LED colour is based on is retrieved over WiFi from the luftdaten website every 5 minutes.
  
This lamp is a plastic pine apple ("ananas"), bought at the "Action" store.
+
This lamp is a soft plastic translucent pine apple ("ananas"), bought at the "Action" store.
  
 
Features:
 
Features:
* The lamp shows particulate matter concentration as a colour, from light blue for low concentration and bright pink for high concentration
+
* The lamp shows PM10 particulate matter concentration as a colour, from dark blue for low concentration to bright pink for high concentration
* The lamp retrieves the PM value over wifi from the the luftdaten website
+
* The lamp retrieves the PM value over wifi from the the luftdaten website, there is a one-time setup to configure your WiFi network so the device can access the internet
* The luftdaten measurement station can be entered at the same time as when wifi credentials are entered.
+
* The lamp automatically determines the nearest luftdaten particulate measurement station, by doing WiFi based geolocation.
 +
* The number/id of the luftdaten station can also be entered manually during the one-time setup.
 +
* The hardware consists of a Wemos D1 mini board (about E3,-), a LED shield and a USB power supply + cable.
 +
* The software supports two different kinds of Wemos D1 mini LED "shield", both the shield with a single LED and the shield with 7 LEDs arranged in a star.  
  
 
Ideas/nice to have:
 
Ideas/nice to have:
* The lamp "breathes" by varying the intensity over time, e.g. a cycle of 10 seconds where the light dims a bit and brightens a bit. Perhaps increase the breathing rate for higher PM.
+
* Use streaming mode of ESP8266HttpClient to parse JSON directly from a stream, avoiding memory problems / stack overflows
* Automatic determination of location by means of wifi location
+
* Built-in web server, with links to historic measurement data of the sensor it's monitoring, link to google maps, etc.
* Remote control over IR
+
** complication: the [https://www.madavi.de/sensor/graph.php?sensor=esp8266-9137604-pms nice graphs on madavi.de] are based on the *hardware id* (not database id), we can't get that automatically
* Use HSV/HSL colour model internally (instead of RGB)
+
** just show a table with all properties in the left column (PM values, WGS84 location) and their values in the right column?
 +
* The lamp "breathes" by varying the intensity over time, e.g. a cycle of 10 seconds where the light dims a bit and brightens a bit
 +
** perhaps increase the breathing rate for higher PM?
 +
** perhaps modulate the colour saturation instead of intensity?
 +
** flash to indicate problems with the particulate matter module, so you can know something is wrong with your Luftdaten sensor and when to power-down/up to reset it again
 +
* some kind of compatibility mode with the stoflamp from stoflamp.nl
 +
 
 +
Next steps:
 +
* Run the software directly on a WiFi-enabled E14 RGB lamp from the Action store. This lamp has the microcontroller already built in. No separate USB power adapter is needed, it runs directly off 230V. See the [[WifiLamp]] project.
 +
 
 +
== Building it ==
 +
[[File:stoflama_parts.jpg|right|thumb|stoflama]]
 +
 
 +
It consists of a few parts:
 +
* a Wemos D1 mini board
 +
* a LED shield, either the one with 1 LED, or the one with 7 LEDs
 +
* a 5V USB charger + USB cable
 +
* a plastic lamp enclosure
  
 
== Operation Manual ==
 
== Operation Manual ==
[[File:ananas_config.png|right|thumb|configuration]]
+
[[File:stoflama.jpg|right|thumb|stoflama]]
  
 
=== Programming ===
 
=== Programming ===
Line 31: Line 51:
 
* flash the software into the Wemos D1 mini, typically from the command line using platformio:
 
* flash the software into the Wemos D1 mini, typically from the command line using platformio:
 
   pio run -t upload
 
   pio run -t upload
 +
 +
This assumes you have platformio installed, this is done on Debian Linux for example, as follows:
 +
  sudo apt-get install python-pip
 +
  sudo pip install platformio
  
 
=== Configuration ===
 
=== Configuration ===
 +
[[File:ananas_config.png|right|thumb|configuration]]
 +
 +
Automatic configuration:
 +
* power up the lamp
 +
* on a mobile phone, connect to the "ESP-PMLAMP" network, and select login
 +
* when presented with the captive portal, select a WiFi network, fill in the WiFi password, leave the luftdaten id field empty, press SAVE
 +
* the closest luftdaten particulate matter sensor will automatically be determined
 +
 +
Manual configuration:
 
* on https://netherlands.maps.luftdaten.info find the particulate matter station you want to follow and note the number of the station, for example "12246"
 
* on https://netherlands.maps.luftdaten.info find the particulate matter station you want to follow and note the number of the station, for example "12246"
* on a mobile phone, connect to the "ESP-STOFANANAS" network, and select login
+
* on a mobile phone, connect to the "ESP-PMLAMP" network, and select login
 
* when presented with the captive portal, select a WiFi network, fill in the WiFi password, AND ALSO fill in the number you looked up earlier, press SAVE
 
* when presented with the captive portal, select a WiFi network, fill in the WiFi password, AND ALSO fill in the number you looked up earlier, press SAVE
* NOTE: when the configuration is ongoing, the LED will be YELLOW, it turns OFF when configuration is done.
+
 
 +
Alternatively:
 +
* make sure at least the WiFi credentials have been entered and saved
 +
* open a console to the serial port of the wemos D1 mini (115200 bps) and enter the following command:
 +
  config auto
 +
* within a few seconds, you should see it prints the current approximate geographic location and the id of the luftdaten station, the id should be non-zero. It is saved in internal memory.
  
 
=== Usage ===
 
=== Usage ===
* Turn on the light while in range of the WiFi network you configured
+
* Power up the lamp while in range of the WiFi network you configured. The LED shows a colour animation when starting up (starting with red and ending with red)
* The LED should start yellow (connecting to the WiFi), then briefly change to OFF (retrieving PM value from Luftdaten), then change to a colour representing a PM concentration
+
* The LED turns off for a short time, then changes to a colour representing a PM concentration
* A new PM measurement is retrieved every minute.
+
* A new PM measurement is retrieved automatically every 5 minutes.
  
 
== Hardware ==
 
== Hardware ==
 
[[File:pl9823.png|right|thumb|pinout]]
 
[[File:pl9823.png|right|thumb|pinout]]
 
The lamp is controlled by an ESP8266, a Wemos D1 mini board.
 
The lamp is controlled by an ESP8266, a Wemos D1 mini board.
The LEDs is an RGB LED with built-in PL9823 controller.
+
The LED is an RGB LED with built-in PL9823 controller.
 +
The PL9823 is compatible with the WS2812B RGB LED as far as I can tell (the WS2812B driver in the FastLED library works with the PL9823).
  
 
Connections (using dupont female-female):
 
Connections (using dupont female-female):
* LED Din to Wemos D1 mini pin D3
+
* LED Din to Wemos D1 mini pin D2
 
* LED Gnd to Wemos D1 mini pin GND
 
* LED Gnd to Wemos D1 mini pin GND
 
* LED Vdd to Wemos D1 mini pin 5V
 
* LED Vdd to Wemos D1 mini pin 5V
 +
 +
This is the same pinout as used by the [https://wiki.wemos.cc/products:d1_mini_shields:ws2812b_rgb_shield Wemos WS2812B RGB shield]
  
 
== Software ==
 
== Software ==
Software is available on [https://github.com/bertrik/stofananas github].
+
=== Getting and building the source code ===
 +
Source code is available on [https://github.com/bertrik/stofananas github].
 +
 
 +
To compile and upload it, I use platform io:
 +
  pio run -t upload
 +
 
 +
You can also compile it with the Arduino IDE, libraries used:
 +
* WiFiManager (v 0.14) is used to manage WiFi connection to the local AP
 +
* ArduinoJSON (v 6.11) for the parsing the luftdaten response
 +
* FastLED (v 3.2.9) is used to control the RGB LED
  
 
=== Luftdaten interface ===
 
=== Luftdaten interface ===
Line 67: Line 117:
 
The software looks for the "P1" (PM10) sensor value in the JSON message and averages all measurements it finds (usually the current one and a previous one).
 
The software looks for the "P1" (PM10) sensor value in the JSON message and averages all measurements it finds (usually the current one and a previous one).
  
=== Arduino libraries ===
+
=== Colour mapping ===
Libraries:
+
Mapping is as follows, with piecewise linear interpolation:
* WiFiManager is used to manage WiFi connection to the local AP
+
* 0 ug/m3: <span style="background:#0000FF>deep blue</span>
* ArduinoJSON for the parsing the luftdaten response
+
* 25 ug/m3: <span style="background:#00F00F>green</span>
* FastLED is used to control the LED
+
* 50 ug/m3: <span style="background:#FFFF00>yellow</span>
 +
* 100 ug/m3: <span style="background:#FF0000>red</span>
 +
* 200 ug/m3: (and higher)<span style="background:#FF0080>purplish</span>

Revision as of 01:04, 11 November 2019

Project StofAnanas
StofAnanas.jpg
Showing particulate matter concentration as a coloured light
Status In progress
Contact bertrik
Last Update 2019-11-11

The concept

The stofananas/stoflama/pmlamp shows airborne particulate matter concentration from the nearest luftdaten citizen science measurement station as a colour on a LED lamp, inspired by http://stoflamp.nl The data that the LED colour is based on is retrieved over WiFi from the luftdaten website every 5 minutes.

This lamp is a soft plastic translucent pine apple ("ananas"), bought at the "Action" store.

Features:

  • The lamp shows PM10 particulate matter concentration as a colour, from dark blue for low concentration to bright pink for high concentration
  • The lamp retrieves the PM value over wifi from the the luftdaten website, there is a one-time setup to configure your WiFi network so the device can access the internet
  • The lamp automatically determines the nearest luftdaten particulate measurement station, by doing WiFi based geolocation.
  • The number/id of the luftdaten station can also be entered manually during the one-time setup.
  • The hardware consists of a Wemos D1 mini board (about E3,-), a LED shield and a USB power supply + cable.
  • The software supports two different kinds of Wemos D1 mini LED "shield", both the shield with a single LED and the shield with 7 LEDs arranged in a star.

Ideas/nice to have:

  • Use streaming mode of ESP8266HttpClient to parse JSON directly from a stream, avoiding memory problems / stack overflows
  • Built-in web server, with links to historic measurement data of the sensor it's monitoring, link to google maps, etc.
    • complication: the nice graphs on madavi.de are based on the *hardware id* (not database id), we can't get that automatically
    • just show a table with all properties in the left column (PM values, WGS84 location) and their values in the right column?
  • The lamp "breathes" by varying the intensity over time, e.g. a cycle of 10 seconds where the light dims a bit and brightens a bit
    • perhaps increase the breathing rate for higher PM?
    • perhaps modulate the colour saturation instead of intensity?
    • flash to indicate problems with the particulate matter module, so you can know something is wrong with your Luftdaten sensor and when to power-down/up to reset it again
  • some kind of compatibility mode with the stoflamp from stoflamp.nl

Next steps:

  • Run the software directly on a WiFi-enabled E14 RGB lamp from the Action store. This lamp has the microcontroller already built in. No separate USB power adapter is needed, it runs directly off 230V. See the WifiLamp project.

Building it

stoflama

It consists of a few parts:

  • a Wemos D1 mini board
  • a LED shield, either the one with 1 LED, or the one with 7 LEDs
  • a 5V USB charger + USB cable
  • a plastic lamp enclosure

Operation Manual

stoflama

Programming

  • connect everything up as indicated under 'hardware' and connect the Wemos D1 board to the USB port of your development PC / laptop
  • flash the software into the Wemos D1 mini, typically from the command line using platformio:
 pio run -t upload

This assumes you have platformio installed, this is done on Debian Linux for example, as follows:

 sudo apt-get install python-pip
 sudo pip install platformio

Configuration

configuration

Automatic configuration:

  • power up the lamp
  • on a mobile phone, connect to the "ESP-PMLAMP" network, and select login
  • when presented with the captive portal, select a WiFi network, fill in the WiFi password, leave the luftdaten id field empty, press SAVE
  • the closest luftdaten particulate matter sensor will automatically be determined

Manual configuration:

  • on https://netherlands.maps.luftdaten.info find the particulate matter station you want to follow and note the number of the station, for example "12246"
  • on a mobile phone, connect to the "ESP-PMLAMP" network, and select login
  • when presented with the captive portal, select a WiFi network, fill in the WiFi password, AND ALSO fill in the number you looked up earlier, press SAVE

Alternatively:

  • make sure at least the WiFi credentials have been entered and saved
  • open a console to the serial port of the wemos D1 mini (115200 bps) and enter the following command:
 config auto
  • within a few seconds, you should see it prints the current approximate geographic location and the id of the luftdaten station, the id should be non-zero. It is saved in internal memory.

Usage

  • Power up the lamp while in range of the WiFi network you configured. The LED shows a colour animation when starting up (starting with red and ending with red)
  • The LED turns off for a short time, then changes to a colour representing a PM concentration
  • A new PM measurement is retrieved automatically every 5 minutes.

Hardware

pinout

The lamp is controlled by an ESP8266, a Wemos D1 mini board. The LED is an RGB LED with built-in PL9823 controller. The PL9823 is compatible with the WS2812B RGB LED as far as I can tell (the WS2812B driver in the FastLED library works with the PL9823).

Connections (using dupont female-female):

  • LED Din to Wemos D1 mini pin D2
  • LED Gnd to Wemos D1 mini pin GND
  • LED Vdd to Wemos D1 mini pin 5V

This is the same pinout as used by the Wemos WS2812B RGB shield

Software

Getting and building the source code

Source code is available on github.

To compile and upload it, I use platform io:

 pio run -t upload

You can also compile it with the Arduino IDE, libraries used:

  • WiFiManager (v 0.14) is used to manage WiFi connection to the local AP
  • ArduinoJSON (v 6.11) for the parsing the luftdaten response
  • FastLED (v 3.2.9) is used to control the RGB LED

Luftdaten interface

The current measurement value of a particular sensor can be determined by parsing the JSON messages retrieved over a REST interface, by performing an HTTP GET on URL

 http://api.luftdaten.info/v1/sensor/<sensor-id>/

where <sensor-id> is the database id used by luftdaten (and visible on their map). The trailing slash in the URL is significant.

For example:

 http://api.luftdaten.info/v1/sensor/12246/

The software looks for the "P1" (PM10) sensor value in the JSON message and averages all measurements it finds (usually the current one and a previous one).

Colour mapping

Mapping is as follows, with piecewise linear interpolation:

  • 0 ug/m3: deep blue
  • 25 ug/m3: green
  • 50 ug/m3: yellow
  • 100 ug/m3: red
  • 200 ug/m3: (and higher)purplish