-
This library is part of Smart Device Project;
-
Is mean to be used with Smart Device App and Smart Device API;
-
Developed for ESP8266 microcontroller.
#include "DHT.h"
#include "ESP8266WiFi.h"
#include "WiFiClient.h"
#include "ESP8266HTTPClient.h"
#include "SmartDevices.h"
#define DHTPIN D1
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int h = 0;
float t = 0;
const char* ssid = ""; //Enter your WIFI ssid
const char* password = ""; //Enter your WIFI password
String server_url = "";// Enter the API endpoint without '/' at the end
String devicesIds[] = {"id1", "id2"}; //Enter your device Id
int size;
// Set up the client objet
WiFiClient client;
HTTPClient http;
SmartDevices smartDevices(server_url, client, http);
void readDht11(){
h = dht.readHumidity();
t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print("Humidity = ");
Serial.print(h);
Serial.print("% ");
Serial.print("Temperature = ");
Serial.print(t);
Serial.println("C ");
}
void setup() {
delay(3000);
Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
smartDevices.initConnection(devicesIds, 1);
delay(1000);
}
void loop() {
readDht11();
String measures[] = {String(h),String(t)};
size = sizeof(measures) / sizeof(String);
smartDevices.sendMeasures(devicesIds[0], measures, size);
delay(5000);
}
✔️ If you've followed the steps and were successful, it's a sign that it worked!
❌ If any of the steps didn't work, something wrong isn't right! (Make an issue)
-
Option 1
- 🍴 Fork this repository!
-
Option 2
- 👯 Clone to your machine.
- Code it! 👨💻👩💻
- 🔃 Create a pull request.
Marcelo Amorim | Caio Souza |
---|---|
- MIT license
- Copyright 2021 © SmartDeviceProductions.