Skip to content

Library for ESP8266 to be used on the Smart Device Project

License

Notifications You must be signed in to change notification settings

marceloams/smart-device-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Smart Device Library


🎯 Objective


📚 Dependencies

This library rely on the following libraries:


📁 Repository structure


⚡ Example

#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);
}

Other Examples


✔️ 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)


🔨 Contribution

Step 1

  • Option 1

    • 🍴 Fork this repository!
  • Option 2

    • 👯 Clone to your machine.

Step 2

  • Code it! 👨‍💻👩‍💻

Step 3

  • 🔃 Create a pull request.

👨‍💻 Authors

Marcelo Amorim Caio Souza
SmartDeviceAppProductions SmartDeviceAppProductions

©️ License

License


About

Library for ESP8266 to be used on the Smart Device Project

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages