Weather Station with Light, Humidity, Temperature: More Data QA/QC

Building Up

4.1 Soldering

I manually soldered each joint. It is not the best way to replicate and mass production. Each board is like an art (jokingly). The reduce the load on-board 3.3V voltage regulator, I added an AMS1117 3.3 regulator to supply to the sensor. Some connection more joints are needed such as GND, 3.3V, 5V in the supply side, SDA and SCL for I2C communication. I found easier to give these places extra space to add more joint later. I were not planning all out before soldering.

And this is the schematics of wiring. Parts are from Adafruit's so that if the parts are from other place, be sure to check to voltage, the voltage regular could be added or removed.

schematic
4.2 Coding

I will go slow to some important parts, but you do have option to download the code from the GitHub and upload to your system right away.

My real configuration are more complex including a Raspberry Pi 3B as the local broker. Other clients communicate with the local broker through unsecured port 1883. Other script running on Raspberry Pi will bridge the message to forward to the server where I host my website. The remote broker are running on secured ports 8883 or 8803, so there is an extra mile to fill in there. Setting up a local web display that runs on Raspberry Pi are much easier. In this tutorial I will provide necessities for this approach.

On remote broker, another Python script will listen to the topic and write the data to SQL database that serves at the web interface. Sounds simple but this process took me 2-3 weeks to get it running. If you get everything running in the first time, I envy you. But if you scratched your head red, the I am with you. It is incredible annoying to figure out what is wrong because so many things can be mis-configurated for such a long pipe-line communication.

The code will include deepsleep procedure to reduce the energy consumption. With a 2000mAh battery, a simpler version could not last overnight. With 5-minute interval wake up and sleeping, a single 18650 battery (rated 2000mAh) could last 4.5 days. The basic code blocks are:

    # include libraries
    # set up instant, variant
    # setup loop
    ## other function will be called when the setup loop runs
    ## deepsleep called
    # main loop but will be never run 
    # other functions such as communication, sampling, simple calculation

Here is another snapshot of the coding construction. The setup function is simple and organized.

void setup() {
        Serial.begin(115200);
        pinMode(RED_PIN, OUTPUT);
        pinMode(BLUE_PIN, OUTPUT);
        
        Serial.println("\nStarting :::: " + String(SENSORNAME));
        setup_wifi();
        delay(100);
        Wire.begin();
        led(BLUE_PIN, 200, 3);
        led(RED_PIN, 200, 3);
        
        setup_ADS1115();
        delay(500);
        get_ds18b20();
        get_DHT22();
        get_Si7021();
        get_light();
        get_BH1750();
        
        delay(100);
        led(BLUE_PIN, 800, 3);
        
        if (debug){
            print_Readout();
        } else {
            Serial.println("\nNo printout, debug = false");
            }
        push_data();
        //  sendState();
        led(BLUE_PIN, 300,5);
        delay(200);
        ESP.deepSleep(3e8); // 60 millions micro seconds, 300 seconds, 5 minutes;
        }

Other functions are placed below the main loop:

code overview

As always, the code is uploaded and hosted in GitHub. The output from Serial Monitor is like this, but not exact. I moved the call function for sampling to the main loop which is run repeatedly. The version of the code above is after the (first) debug stage.

serial readouts
4.3 Other Setup

This weather station using MQTT protocol to transfer data from the station to the local broker, so you need to setup the local broker, user and password. Here are some useful links:

  • What is the MQTT Implementation looks like?
  • Setup MQTT Broker
  • Upload Arduino code to ESP8266-01
  • Get a new (Raspberry) Pi, let get started!
  • With the connection to Internet and the local broker, running with a fix interval (no deepSleep yet), yields an output:

    final readout