Download micro from digitalai/Colic: direct link, hf CLI and curl.
- Browser
- Download file 2.18 kB
-
https://huggingface.co/spaces/digitalai/Colic/resolve/main/micro
- Command line
-
hf download hf://spaces/digitalai/Colic/micro
-
curl -L -o micro https://huggingface.co/spaces/digitalai/Colic/resolve/main/micro
2.18 kB
| ## uno | |
| #include "DHT.h" | |
| #define DHTPIN 2 // D2 for Arduino | |
| #define DHTTYPE DHT11 | |
| #define BAUD_RATE 9600 | |
| DHT dht(DHTPIN, DHTTYPE); | |
| void setup() { | |
| Serial.begin(BAUD_RATE); // Set baud rate for serial communication | |
| dht.begin(); | |
| } | |
| void loop() { | |
| float val = dht.readHumidity(); | |
| float chk = dht.readTemperature(); | |
| if (isnan(h) || isnan(t)) { | |
| Serial.println("Failed to read from DHT sensor!"); | |
| } else { | |
| // Send data to ESP8266 | |
| Serial.print(chk); | |
| Serial.print(","); | |
| Serial.println(t); | |
| } | |
| delay(2000); // Wait a few seconds between measurements | |
| } | |
| ### ٍEsp8266 | |
| #include <ESP8266WiFi.h> | |
| #include <WiFiClientSecure.h> | |
| #include <ESP8266HTTPClient.h> | |
| const char* ssid = "WIFI_SSID"; | |
| const char* password = "WIFI_PASSWORD"; | |
| String API_URL = "API_URL"; | |
| String API_KEY = "API_KEY"; | |
| String TableName = "maintable"; | |
| const int httpsPort = 443; | |
| int sendingInterval = 1200; | |
| HTTPClient https; | |
| WiFiClientSecure client; | |
| void setup() { | |
| Serial.begin(9600); | |
| delay(10); | |
| Serial.println(); | |
| Serial.println("Connecting to "); | |
| Serial.println(ssid); | |
| WiFi.begin(ssid, password); | |
| while (WiFi.status() != WL_CONNECTED) { | |
| delay(500); | |
| Serial.print("."); | |
| } | |
| Serial.println(""); | |
| Serial.println("WiFi connected"); | |
| Serial.println("IP address: "); | |
| Serial.println(WiFi.localIP()); | |
| client.setInsecure(); | |
| } | |
| void loop() { | |
| if (WiFi.status() == WL_CONNECTED) { | |
| if (Serial.available() > 0) { | |
| String data = Serial.readStringUntil('\n'); | |
| float val, chk; | |
| sscanf(data.c_str(), "%f,%f", &val, &chk); | |
| https.begin(client, API_URL + "/rest/v1/" + TableName); | |
| https.addHeader("Content-Type", "application/json"); | |
| https.addHeader("Prefer", "return=representation"); | |
| https.addHeader("apikey", API_KEY); | |
| https.addHeader("Authorization", "Bearer " + API_KEY); | |
| int httpCode = https.POST("{\"val\":" + String(val) + ",\"chk\":" + String(chk) + "}"); | |
| String payload = https.getString(); | |
| Serial.println(httpCode); | |
| Serial.println(payload); | |
| https.end(); | |
| } | |
| } else { | |
| Serial.println("Error in WiFi connection"); | |
| } | |
| delay(1000 * sendingInterval); | |
| } |