Devices & Components
Nanomesher Human Machine Interface
Resistor 4.7k Ohm
Wemos D1 Mini
Sensirion SHT31
Jumper wires (generic)
Software & Tools
Arduino IDE
Project description
Code
WeatherSender
arduino
Arduino code for reading Humidity and Temperature from SHT31 and update data on the display. Before using the code, change: - SSID / PASSWORD - ip address in http://192.168.1.12/TextSetText?p=0&n=line1&v= - line1 - line4 depending on location of the sensor in http://192.168.1.12/TextSetText?p=0&n=line1&v=
1#include <Arduino.h> 2 3#include <ESP8266WiFi.h> 4#include <ESP8266WiFiMulti.h> 5#include 6 <Wire.h> 7#include "Adafruit_SHT31.h" 8#include <ESP8266HTTPClient.h> 9 10#define 11 USE_SERIAL Serial 12 13ESP8266WiFiMulti WiFiMulti; 14 15float t = 0; 16float 17 h = 0; 18 19 20Adafruit_SHT31 sht31 = Adafruit_SHT31(); 21 22void setup() { 23 24 25 USE_SERIAL.begin(115200); 26 // USE_SERIAL.setDebugOutput(true); 27 28 29 USE_SERIAL.println(); 30 USE_SERIAL.println(); 31 USE_SERIAL.println(); 32 33 34 for(uint8_t t = 4; t > 0; t--) { 35 USE_SERIAL.printf("[SETUP] WAIT 36 %d...\ 37", t); 38 USE_SERIAL.flush(); 39 delay(1000); 40 } 41 42 43 WiFiMulti.addAP("SSID", "PASSWORD"); 44 45} 46 47void loop() { 48 // 49 wait for WiFi connection 50 if((WiFiMulti.run() == WL_CONNECTED)) { 51 52 53 t = sht31.readTemperature(); 54 h = sht31.readHumidity(); 55 56 57 58 char temp[10]; 59 dtostrf(t,1,1,temp); 60 61 char 62 humid[10]; 63 dtostrf(h,1,1,humid); 64 65 String url = 66 "http://192.168.1.12/TextSetText?p=0&n=line1&v="; 67 68 HTTPClient 69 http; 70 71 USE_SERIAL.print("[HTTP] begin...\ 72"); 73 http.begin(url 74 + temp + "c " + humid + "%"); //HTTP 75 76 USE_SERIAL.print("[HTTP] 77 GET...\ 78"); 79 // start connection and send HTTP header 80 int 81 httpCode = http.GET(); 82 83 // httpCode will be negative on error 84 85 if(httpCode > 0) { 86 // HTTP header has been send and Server 87 response header has been handled 88 USE_SERIAL.printf("[HTTP] GET... 89 code: %d\ 90", httpCode); 91 92 // file found at server 93 if(httpCode 94 == HTTP_CODE_OK) { 95 String payload = http.getString(); 96 USE_SERIAL.println(payload); 97 98 } 99 } else { 100 USE_SERIAL.printf("[HTTP] GET... 101 failed, error: %s\ 102", http.errorToString(httpCode).c_str()); 103 } 104 105 106 http.end(); 107 } 108 109 delay(10000); 110} 111
WeatherSender
arduino
Arduino code for reading Humidity and Temperature from SHT31 and update data on the display. Before using the code, change: - SSID / PASSWORD - ip address in http://192.168.1.12/TextSetText?p=0&n=line1&v= - line1 - line4 depending on location of the sensor in http://192.168.1.12/TextSetText?p=0&n=line1&v=
1#include <Arduino.h> 2 3#include <ESP8266WiFi.h> 4#include <ESP8266WiFiMulti.h> 5#include <Wire.h> 6#include "Adafruit_SHT31.h" 7#include <ESP8266HTTPClient.h> 8 9#define USE_SERIAL Serial 10 11ESP8266WiFiMulti WiFiMulti; 12 13float t = 0; 14float h = 0; 15 16 17Adafruit_SHT31 sht31 = Adafruit_SHT31(); 18 19void setup() { 20 21 USE_SERIAL.begin(115200); 22 // USE_SERIAL.setDebugOutput(true); 23 24 USE_SERIAL.println(); 25 USE_SERIAL.println(); 26 USE_SERIAL.println(); 27 28 for(uint8_t t = 4; t > 0; t--) { 29 USE_SERIAL.printf("[SETUP] WAIT %d...\ 30", t); 31 USE_SERIAL.flush(); 32 delay(1000); 33 } 34 35 WiFiMulti.addAP("SSID", "PASSWORD"); 36 37} 38 39void loop() { 40 // wait for WiFi connection 41 if((WiFiMulti.run() == WL_CONNECTED)) { 42 43 t = sht31.readTemperature(); 44 h = sht31.readHumidity(); 45 46 47 char temp[10]; 48 dtostrf(t,1,1,temp); 49 50 char humid[10]; 51 dtostrf(h,1,1,humid); 52 53 String url = "http://192.168.1.12/TextSetText?p=0&n=line1&v="; 54 55 HTTPClient http; 56 57 USE_SERIAL.print("[HTTP] begin...\ 58"); 59 http.begin(url + temp + "c " + humid + "%"); //HTTP 60 61 USE_SERIAL.print("[HTTP] GET...\ 62"); 63 // start connection and send HTTP header 64 int httpCode = http.GET(); 65 66 // httpCode will be negative on error 67 if(httpCode > 0) { 68 // HTTP header has been send and Server response header has been handled 69 USE_SERIAL.printf("[HTTP] GET... code: %d\ 70", httpCode); 71 72 // file found at server 73 if(httpCode == HTTP_CODE_OK) { 74 String payload = http.getString(); 75 USE_SERIAL.println(payload); 76 } 77 } else { 78 USE_SERIAL.printf("[HTTP] GET... failed, error: %s\ 79", http.errorToString(httpCode).c_str()); 80 } 81 82 http.end(); 83 } 84 85 delay(10000); 86} 87
Downloadable files
WeatherSender Schematic
A very simple weather logger which uses SHT3x sensor with i2c interface. The Arduino software will read data and send the data to Nanomesher HMI via HTTP
WeatherSender Schematic

Comments
Only logged in users can leave comments