include "DHT.h"
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
DHT dht;
ESP8266WiFiMulti WiFiMulti;
uint8_t LED_Pin =D1;
char TEMP_SENSOR[]="http://app.gnanodaya.org/openioe/api/updatedevicevalue/xxxxxx/xxx/xxx/";
char HUMIDITY_SENSOR[]="http://app.gnanodaya.org/openioe/api/updatedevicevalue/xxxxxx/xxx/xxx/";
char DHT_LED[]="http://app.gnanodaya.org/openioe/api/showdevicevalue/xxxxxxx/xxx/xxx/";
void setup() {
Serial.begin(9600);
pinMode(LED_Pin, OUTPUT);
dht.setup(D4);
WiFi.mode(WIFI_STA);
WiFiMulti.addAP("xxxxx", "xxxxx");
}
void loop() {
delay(dht.getMinimumSamplingPeriod());
if ((WiFiMulti.run() == WL_CONNECTED)) {
float humidity = dht.getHumidity();
float temperature = dht.getTemperature();
WiFiClient client;
HTTPClient http;
if (http.begin(client, TEMP_SENSOR+String(temperature))) {
int httpCode = http.GET();
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
}
}
http.end();
}
if (http.begin(client, HUMIDITY_SENSOR+String(humidity))) {
int httpCode = http.GET();
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
}
}
http.end();
}
if (http.begin(client, DHT_LED)) {
int httpCode = http.GET();
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
if (payload=="1"){
digitalWrite(LED_Pin, HIGH);
}
else if (payload.equals("0")){
digitalWrite(LED_Pin, LOW);
}
else{
digitalWrite(LED_Pin, LOW);
}
}
}
http.end();
}
}
}
from openioe.openioe_apis import *
oi=openioe_apis()
oi.APIKey='xxxxxxxxxx'
oi.DeviceID=xxx
oi.DevicePin=xxx
SensorData,ResposeCode=oi.ReadValue()
print(SensorData)
print(ResposeCode)
oi.APIKey='xxxxxxxxxx'
oi.DeviceID=12
oi.DevicePin=27
oi.Data=0
SensorData,ResposeCode=oi.WriteValue()
print(SensorData)
print(ResposeCode)