Last active
February 15, 2022 04:03
-
-
Save auriza/245382917c2da93e03a14a4b2a7241fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <WEMOS_SHT3X.h> | |
#include <Adafruit_SSD1306.h> | |
#include <ESP8266WiFi.h> | |
#include <ESP8266HTTPClient.h> | |
SHT3X sht30(0x45); | |
Adafruit_SSD1306 oled(-1); | |
int i = 0; | |
void setup() { | |
pinMode(LED_BUILTIN, OUTPUT); | |
Serial.begin(115200); | |
oled.begin(); | |
oled.setTextColor(WHITE); | |
WiFi.begin("Ilkomerz_GreenHouse", "ilkomgr33n1P8"); | |
while (WiFi.status() != WL_CONNECTED) delay(500); | |
} | |
void loop() { | |
if (sht30.get() == 0) | |
show_temp(); | |
if (WiFi.status() == WL_CONNECTED && i%12 == 0) { | |
digitalWrite(LED_BUILTIN, LOW); | |
show_wifi(); | |
send_data(); | |
digitalWrite(LED_BUILTIN, HIGH); | |
} | |
oled.display(); | |
delay(5000); i++; | |
} | |
void send_data() { | |
WiFiClient client; | |
HTTPClient http; | |
http.begin(client, "http://api.thingspeak.com/update"); | |
http.addHeader("Content-Type", "application/x-www-form-urlencoded"); | |
int resp_code = http.POST("api_key=XXXXXXXXXXXXXXXX&field1=" + String(sht30.cTemp) + "&field2=" + sht30.humidity + "&field3="+ WiFi.RSSI()); | |
http.end(); | |
Serial.print("[HTTP] "); Serial.println(resp_code); | |
oled.setCursor(0, 36); oled.print(resp_code); | |
if (resp_code == 302) { | |
http.begin(client, "http://1.1.1.3/ac_portal/login.php"); | |
http.addHeader("Content-Type", "application/x-www-form-urlencoded"); | |
http.POST("opr=pwdLogin&userName=krs002&pwd=krs2015"); | |
http.end(); | |
} | |
} | |
void show_temp() { | |
Serial.print("[SHT30] Temp: "); | |
Serial.print(sht30.cTemp); | |
Serial.print(", RH: "); | |
Serial.println(sht30.humidity); | |
oled.clearDisplay(); | |
oled.setCursor(0, 0); | |
oled.setTextSize(2); | |
oled.print(int(sht30.cTemp)); | |
oled.setTextSize(1); | |
oled.println("\""); | |
oled.print(" ."); | |
oled.println(int((sht30.cTemp - int(sht30.cTemp)) * 10)); | |
oled.println(); | |
oled.println(); | |
oled.print(" "); | |
oled.setTextSize(2); | |
oled.print(sht30.humidity, 0); | |
oled.setTextSize(1); | |
oled.println(); | |
oled.print(" %"); | |
} | |
void show_wifi() { | |
Serial.print("[WiFi] IP: "); | |
Serial.print(WiFi.localIP()); | |
Serial.print(", RSSI: "); | |
Serial.println(WiFi.RSSI()); | |
//oled.setCursor(0, 20); oled.print(WiFi.localIP()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment