Closed jhonnybonny closed 2 years ago
UPD : ESP code :
const char ssid = "имя сети"; const char password = "пароль сети вай-фай";
ESP8266WebServer server(80); DHT dht(DHTPIN, DHTTYPE, 11); // 11 works fine for ESP8266
float humidity, temp_c; // Values read from sensor
// Generally, you should use "unsigned long" for variables that hold time unsigned long previousMillis = 0; // will store last temp was read const long interval = 2000; // interval at which to read sensor
void handle_root() { server.send(200, "text/plain", "Homebridge http Temperature and humidity Sensor, read from /dht"); delay(100); }
void setup(void) { Serial.begin(115200); // Serial connection from ESP-01 via 3.3v console cable dht.begin(); // initialize temperature sensor
// Connect to WiFi network WiFi.begin(ssid, password); IPAddress ip(192, 168, 1, 199); IPAddress gateway(192, 168, 1, 1); IPAddress subnet(255, 255, 255, 0); WiFi.config(ip, gateway, subnet); Serial.print("\n\r \n\rWorking to connect");
// Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("DHT data Reading Server"); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP());
server.on("/", handle_root);
server.on("/dht", []() { gettemperature(); server.send(200, "text/json", "{\n" "\"temperature\": " + String(temp_c) + ",\n ""\"humidity\": " + String(humidity) + "" "\n}"); });
server.begin(); Serial.println("HTTP server started"); }
void loop(void) { server.handleClient(); }
void gettemperature() { unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; humidity = dht.readHumidity(); // Read humidity (percent) temp_c = dht.readTemperature(false); // Read temperature as Fahrenheit if (isnan(humidity) || isnan(temp_c)) { Serial.println("Failed to read from DHT sensor!"); return; } } }
http://192.168.1.199/dht show { "temperature": 25.90, "humidity": 39.00 }
I have problem my script :
{ "bridge": { "name": "HomeBridge", "username": "74:2f:68:32:34:4d", "port": 51826, "pin": "928-27-796" }, "description": "Example configuration file for homebridge-httptemperaturehumidity plugin", "accessories": [ { "accessory": "AdvancedHttpTemperatureHumidity", "name": "Living Room", "url": "http://192.168.1.199/dht", "sendimmediately": "", "http_method": "GET" } ], "platforms": [ { "platform": "config", "name": "Config", "port": 8080, "sudo": true, "restart": "sudo -n systemctl restart homebridge", "log": { "method": "systemd", "service": "homebridge" } } ], "name": "DHT", "accessory": "AdvancedHttpTemperatureHumidity" }
Homebridge show error : [8/28/2021, 4:32:33 PM] [DHT] Get Temperature failed: options.uri is a required argument