Statistics: Posted by blackbird.0360 — Sun Nov 14, 2021 11:57 am
Statistics: Posted by Jacques1983 — Wed May 05, 2021 11:02 am
Statistics: Posted by drmpf — Mon Sep 07, 2020 9:53 pm
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <ArduinoHttpClient.h>
#include <Arduino.h>
const char* ssid = "your-ssid"; // Your WiFi ssid
const char* password = "your-password"; //Your Wifi password
// Get this secret key from the wia dashboard. It should start with `d_sk`
const char* device_secret_key = "your-device-secret-key";
// Wia API parameters
char server[] = "api.wia.io";
char path[] = "/v1/events";
int port = 80;
WiFiClient client;
int status = WL_IDLE_STATUS;
StaticJsonBuffer<200> jsonBuffer;
HttpClient httpClient = HttpClient(client, server, port);
JsonObject& root = jsonBuffer.createObject();
String response;
int statusCode = 0;
String dataStr;
const int ANALOG_PIN = 0;
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
WiFi.begin(ssid, password);
Serial.print("Attempting to connect to SSID: ");
Serial.print(ssid);
// attempt to connect to WiFi network:
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
// wait 5 seconds for connection:
delay(5000);
}
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("connecting...");
}
// Thing function runs continiously
void loop() {
root["name"] = "moisture";
root["data"] = analogRead (ANALOG_PIN);
// if you get a connection, report back via serial:
if (client.connect(server, port)) {
sendToWia(root);
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
delay(1000*15*60); // Wait for 15 minutes to post again
}
// Adds the correct headers for HTTP and sends Data to Wia
void sendToWia(JsonObject& data) {
data.printTo(dataStr);
httpClient.beginRequest();
httpClient.post(path);
httpClient.sendHeader("Content-Type", "application/json");
httpClient.sendHeader("Content-Length", data.measureLength());
httpClient.sendHeader("Authorization", "Bearer " + String(device_secret_key));
httpClient.beginBody();
httpClient.print(dataStr);
httpClient.endRequest();
}
// Check moisture levels
if (input.body.data && input.body.data < 500) {
// Plant is thirsty
output.process = true;
} else {
// Plant is ok
output.process = false;
}
// Check moisture levels
if (input.body.data && input.body.data < 500) {
// Plant is thirsty
output.body.data = "Thirsty";
} else {
// Plant is ok
output.body.data = "Ok";
}
Statistics: Posted by austinspivey — Wed Jul 11, 2018 6:10 am
SendEmail emailAccount("smtp.gmail.com", 465, "yourname@gmail.com", "password", 5000, true);
boolean emailSend = emailAccount.send("<yourname@gmail.com>", "<receipient@server.dom>", "subject","message");
Statistics: Posted by penatenjoe — Sun Mar 18, 2018 11:47 am
Statistics: Posted by michael3 — Fri Feb 16, 2018 6:18 am
Statistics: Posted by tony1tf — Mon Feb 27, 2017 2:32 pm
Statistics: Posted by hilogic — Sun Feb 12, 2017 2:41 am
Statistics: Posted by Priyanka Dookie — Tue Jan 24, 2017 8:06 pm
Statistics: Posted by Pergex — Mon Nov 07, 2016 9:22 am
Statistics: Posted by Jose Gonzalez — Sun Oct 23, 2016 10:38 pm
Statistics: Posted by ohgary — Sun Sep 18, 2016 9:50 am
Statistics: Posted by CFM04 — Thu Aug 25, 2016 12:28 am
Statistics: Posted by CFM04 — Wed Aug 24, 2016 4:07 pm
Statistics: Posted by Barnabybear — Wed Aug 24, 2016 2:54 pm
Statistics: Posted by vlost — Sun Aug 14, 2016 8:58 am
Statistics: Posted by andreazo — Tue Jul 26, 2016 4:03 am
Statistics: Posted by Touliloup — Sun May 22, 2016 3:10 am
Statistics: Posted by hexadec — Thu May 19, 2016 2:30 pm
Statistics: Posted by hexadec — Thu May 19, 2016 12:58 pm