coderpussy / SolarTherm-WIFI-Local-Admin

Just enough local network storage measured sensor data and OTA update for Solar Powered WIFI weather station V2
MIT License
1 stars 1 forks source link
esp8266 esp8266httpupdate iot magicmirror2 ota wemos-d1-mini wifi-weather-station

SolarTherm WiFi Local Admin aka. Solar Powered WiFi Weather Station V2 (IoT device)

A solar powered, wifi connected thermometer implemented with ESP8266 and BME280.

Features

Solar Powered WiFi Weather Station is:

SolarTherm WiFi Local Admin is able to:

SolarTherm WiFi Local Admin isn't:

On this page

(This Table of Contents was manually created by myself. 【ツ】)

ToDo

A lot. Will come soon.

Update

2021-03-11

Getting started

Before you really start

This project is really early development stage and need improvements everywhere especially on security aspects. It is working in my environment with 2 of this wifi IoT devices. This means it is possible to replicate it on other devices too.

If you need external services like ThingSpeak, Blynk, IFTTT or MQTT you should use the original Arduino Sketch or clones around this project. I'm personally not using this services for such kind of project.

For example:

Hardware

Build the hardware recommended by Open Green Energy in his Solar Powered WiFi Weather Station v2.0 project.

Here i have some images from my SolarTherm thermometer devices (cases from Debasish Dutta and Marc Stähli):

Software

This project was built with love <3 and the Arduino IDE to compile and upload it to the Wemos board.
You have to install the following libraries this project depends on to your development environment:

Configuration

Rename the config.sample.h file to config.h, and modify the values.
If you want to use more than one device then rename the file to something like config-one.h and config-two.h and so on.
Declare the correct file in solartherm-wifi-local-admin.ino (comment out existing others declared there). You can only have one device config to build the binary.

See the sections below for more information about the particular features that can be configured in this file.

After turning on the device the first time it will enter into configuration mode.
In configuration mode SolarTherm acts as a WiFi access point.

The SSID name and the password to connect to this access point can be specified in the WIFI_AP_SSID and WIFI_AP_PASSWORD parameters in config.h.
Use your computer to connect to this network, then navigate to http://192.168.4.1 in your web browser to open the configuration portal where you can select the preferred wireless network and set the WiFi password for SolarTherm.

Important: SolarTherm will wait for user interaction only for 60 minutes on the configuration portal, then restarts automatically.
This timeout can be configured in the WIFI_CONFIG_PORTAL_TIMEOUT_SECONDS parameter in config.h.

Sending measured data

SolarTherm collects sensor data and forwards them to local network storage or MagicMirror.

Local network storage

Nearly every local network storage with Apache, PHP, MySQL and filesystem write permissions are possible e.g. RPI.
LAMP stack should not that old. Something newer like actual Raspbian light with manually installed and properly configured services.
Don'forget to secure up you stack if you want to call the webpage with measured and styled data from outside your local network.

If you want to have this as docker installation i'm sure you will find what sweats your needs. I'm not going to provide or support it.

Configuration

The explanation is not done well. I have to correct it and explain some more detailed steps in the future.
To set up the config files on you local network LAMP stack:

  1. Copy the content of admin folder directly to the location on your LAMP stack webroot or subfolder.
  2. Create a API key with PHP password_hash generator generate-password.php located in admin folder
    • S47TnP3pp3R should a self defined salt what you have to set inside remote-temperature.php
    • you should delete the file from the folder after generation
  3. Execute solartherm.sql located in admin folder on your MySQL Server command line or with phpMyAdmin if installed, to create the needed database.
  4. In remote-temperature.php file you have to enter your MySQL database credentials (here i use only localhost if you want to use something else feel free to adjust it)
  5. If you want to have a styled webpage with your measured data you have to enter the database credentials in the get-data.php file too.
  6. In SolarTherm's config.h specify:
    • the URL where to send the data LOCAL_STORAGE_HOST
    • hostname for device identification LOCAL_STORAGE_HOSTNAME
    • and API key LOCAL_STORAGE_API_KEY you created in step 2.

That's it! In every measurement cycle SolarTherm will push the data to your local network storage.

Web Interface

Just put your database credentials where you store your measured SolarTherm data in get-data.php. If your LAMP is properly configured you can open you web browser and point to the URL you specified in your webserver configuration (virtual host whatever).

You will get a responsive webpage like the following image:

At this moment i only provide german language in the index.html file. Feel free to adjust this for your own content. Webpage was tested with Chrome and Firefox. Responsive design should work on mobiles too.

Limitation

Will come soon

MagicMirror

Magic Mirror (known as MagicMirror²) is an open source, modular smart mirror platform, and SolarTherm is able to push measured temperature, humidity and battery level data to MagicMirror to display them immediately.

An example display of the measured data on MagicMirror may look like this:

Configuration

To set up the SolarTherm MagicMirror connection follow these steps:

  1. Install the MMM-RemoteTemperature module on your MagicMirror (multiple definitions are possible).
  2. Configure the module as you prefer.
  3. In SolarTherm's config.h specify:
    • the protocol, address and host in the MAGIC_MIRROR_HOST parameter.
    • sensorId to identify device on MagicMirror module config MAGIC_MIRROR_SENSORID

That's it! In every measurement cycle SolarTherm will push the data to your MagicMirror.

Limitation

Will come soon

Over-the-air updates (OTA)

ESP8266 supports over the air updates out of the box, so you can load the firmware to the ESP using Wi-Fi connection rather than a serial port.
In this project only the ESP8266httpUpdate from OTA is available because all other solutions are not suitable due to the deep sleep functionality what is used in this project.

Security disclaimer

Make sure you read the Security disclaimer and other security related sections in the official documentation to understand the risks!

Prerequisites

Limitations

In this stage the over the air update only receive over unsecure protocol (http instead of https) what is no problem in my local network because i don't need it SSL based.

If you want a secure SSL connection transfer for your binary SolarTherm builds you have to extend the ota-updater.cpp to provide a security parameter.

It is somehow risky to use it with webspace hoster due to the scripts on LAMP stack side. They are more drafts and inspiration for further development.

Steps

  1. Customize the parameters in config.h:
    • URL of update host OTA_UPDATE_HOST (could also IP address or Dynamic DNS)
    • use Port OTA_UPDATE_PORT
    • Path on your webroot where the update script ota-update.php is located OTA_UPDATE_SCRIPT_PATH
    • defines the name for your device OTA_UPDATE_VERSION to identify the correct *.bin sketch file
  2. Define the MAC address of your devices inside the PHP array config ota-update.php with the name you defined in config.h
  3. Build the device binary file with your Arduino IDE, name the file you defined under OTA_UPDATE_VERSION
  4. Upload the file to your webroot defined in step 1 for example: solartherm-ota/bin folder
  5. Load the initial version of the code to the ESP through USB.
  6. Device should reset automatically after transfer

How it works

Every time you build a new binary you get a new md5 checksum for your compiled file.

Troubleshooting

Monitoring the upload

During upload your ESP device will send debug log messages through the serial port. So if OTA does not work, connect your device to your computer, start a serial monitoring tool (e.g. Termite), and start the OTA update through the wireless network.

You can customize the messages in the ota-updater.cpp file.

Acknowledgements

Thanks to Open Green Energy for sharing his Solar Powered WiFi Weather Station v2.0 project.
Thanks to Marc Stähli 3KUdelta for his thingiverse STL's and some code inspiration
Thanks to György Balássy balassy for the base Arduino code
Thanks to Jonas Badalic for his base web frontend code

And all other guys where i have stolen code snippets or ideas or inspirations to make some things possible. ;-P

ℓ٥ﻻ ﻉ√٥υ all ❤◦.¸¸.◦✿

About the author

This project is maintained by Maja Aurora Pieper.