Moved ESP aRest project to sensornode_aRest.

New sensornode with http.get function
This commit is contained in:
2017-09-16 17:48:28 +02:00
parent 792e300186
commit 4430a92f17
5 changed files with 478 additions and 43 deletions

View File

@@ -1,11 +1,8 @@
#include "DHT.h"
#include <ESP8266WiFi.h>
#include "aREST.h"
#include <climits>
#include <ESP8266HTTPClient.h>
//If the debug macro is enabled, there's a freeMemory routine
//Check if this resolves the crashes...
#define DEBUG_MODE 1
#include <climits>
//DHT settings:
@@ -25,21 +22,10 @@
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);
// Create aREST instance
aREST rest = aREST();
// WiFi settings:
const char* ssid = "Your_SSID";
const char* password = "Your_Password";
#define LISTEN_PORT 80
// Create an instance of the server
WiFiServer server(LISTEN_PORT);
// Variables to be exposed to the API
float temperature;
float humidity;
const char* ssid = "Klenkschachtel";
const char* password = "KS!;3k@S$h=?AL";
//milli counter
@@ -60,15 +46,6 @@ void setup() {
//dht driver initialization
dht.begin();
//Expose variables to the rest api
rest.variable("temperature", &temperature);
rest.variable("humidity", &humidity);
// Set a ID (ID must be greater than 0)
rest.set_id("1");
rest.set_name("sensornode");
// Connect to WiFi
Serial.println("Connecting to wlan");
WiFi.begin(ssid, password);
@@ -78,10 +55,6 @@ void setup() {
}
Serial.println("\nWiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
@@ -102,9 +75,14 @@ void loop() {
Serial.println("Failed to read from DHT sensor!");
return;
} else {
//set the new values
humidity = h;
temperature = t;
// Initialize the client library
HTTPClient client;
// Make a HTTP request:
String url = "http://raspitemp:1337/abshum/" + String(t) + "/" + String(h);
client.begin(url);
client.GET();
client.end();
}
//set new milli counter
@@ -115,16 +93,9 @@ void loop() {
millitotal = 0;
}
}
// Handle REST calls
WiFiClient client = server.available();
if (!client) {
return;
}
while(!client.available()){
delay(1);
}
rest.handle(client);
//ESP.deepSleep(MEASURESECONDS * 1000);
//Let the esp chill a bit
delay(100);
}