I read an article about good temperature to sleep in. The article said temperature between 18.3 and 22.2 c is best temperature for human to sleep in. So I will make a temperature logger and sleep temperature checker: Milkbox.

I chose Wemos D1 mini and Arduino MKR WiFi 1010 for this project. Arduino MKR WiFi 1010 is easy to use. Here I focused on the things I learned on Wemos D1 mini.

To use HTTPS on ESP8266, there are two things need to be considered.

1) encrypt all traffic over pubic network (Must)

2) create trust (Optional)

Let WiFiClientSecure library do the first job. We don’t need a vaild CA because server will send one to our device at beginning of each connection. RSA key and Cert is delivered while connection is ready.


For second job, due to ESP8266 has no storage for CA cert, we need to hard-code either fingerprint or CA cert in code sketch if we want to check the validity of CA from server.

  1. Use fingerprint (quick, but only valid for few months)
  2. Use CA (recommend, use root CA if don’t want to change sketch frequently)

I chose first method to implement it.

I also used ArduinoJson library to handle with request. Due to the memory limit on D1, I calculate the size of json by below tool:

https://arduinojson.org/v5/assistant

Here is the hole I fell into…. After few hours and tons of trials and errors, I found the disclaimer on the library page….

Testing and building the circuit and its home. I used SHT30 temperature and humidity sensor. It has I2C interface to D1. The value of sensor will be sent every 30 mins. There is also a PIR sensor and a button to check whether it is “good temperature to sleep” now. If it is, green led will light on.

Source code: