Comments (2)
from iot-smart-temperature-switch-with-alexa-nodemcu.
Ok,
so the Heroku Applications seems to work now, but I don't know If there is anything wrong with my Code or with my Alexa Skill. Btw I just need this to work with the Temperature Sensor so I don't need the part with the Relay etc.
My Code changed to just working with the Temperature Sensor
#include "DHTesp.h"
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WebSocketsClient.h>
#include <Hash.h>const char* ssid = "BLURED";
const char* password = "BLURED";
char host[] = "herokusensor.herokuapp.com";#define dht_dpin 16
DHTesp dht;
int port = 80;
char path[] = "/ws";
ESP8266WiFiMulti WiFiMulti;
WebSocketsClient webSocket;
DynamicJsonBuffer jsonBuffer;
int pingCount = 0;
void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) { //uint8_t *switch(type) { case WStype_DISCONNECTED: Serial.println("Disconnected! "); Serial.println("Connecting..."); webSocket.begin(host, port, path); webSocket.onEvent(webSocketEvent); break; case WStype_CONNECTED: { Serial.println("Connected! "); webSocket.sendTXT("Connected"); } break; case WStype_TEXT: Serial.println("Got data"); processWebScoketRequest((char*)payload); break; case WStype_BIN: hexdump(payload, length); Serial.print("Got bin"); webSocket.sendBIN(payload, length); break; }
}
void setup() {
dht.setup(16);
Serial.begin(115200);
Serial.setDebugOutput(true);for(uint8_t t = 4; t > 0; t--) { delay(1000); } Serial.println(); Serial.println(); Serial.print("Connecting to "); WiFiMulti.addAP(ssid, password); while(WiFiMulti.run() != WL_CONNECTED) { Serial.print("."); delay(100); } Serial.println("Connected to wi-fi"); webSocket.begin(host, port, path); webSocket.onEvent(webSocketEvent);
}
void loop() {
getTemp();
webSocket.loop();
delay(2000);
if (pingCount > 20) {
pingCount = 0;
webSocket.sendTXT(""heartbeat":"keepalive"");
}else {pingCount += 1;}
}void processWebScoketRequest(String data){
String jsonResponse = "{"version": "1.0","sessionAttributes": {},"response": {"outputSpeech": {"type": "PlainText","text": ""},"shouldEndSession": true}}";
JsonObject& root = jsonBuffer.parseObject(data);
String query = root["query"];
String message="";
Serial.println(data);if(query == "cmd"){ //if query check state String value = root["value"]; Serial.println("Recieved command!"); if(value=="on"){ message = "{\"state\":\"ON\"}"; }else if (value=="off"){ message = "{\"state\":\"OFF\"}"; }else if (value=="deactivate"){ //deactivate trigger }else{ String object = root["object"]; //set trigger for temp and humidity } jsonResponse.replace("<text>", "It is done"); }else if(query == "?"){ //if command then execute Serial.println("Recieved query!"); String value = root["value"]; //Serial.print("Value-->"); //Serial.print(value); if(value=="feuchtigkeit"){ //response with current humidity DHT.humidity Serial.println("Humidity response..."); jsonResponse.replace("<text>", "current humidity is " + String(dht.getHumidity()) + " percent"); }else if(value=="temperatur"){ //response with current temperature DHT.temperature /Celcius2Fahrenheit(DHT.temperature) Serial.println("Temp response..."); jsonResponse.replace("<text>", "current temperature is " + String(dht.getTemperature())+ " fahrenheit"); } }else{//can not recognized the command Serial.println("Command is not recognized!"); } //jsonResponse.replace("<text>", "Garage door " + instance + " is " + message ); Serial.print("Sending response back"); Serial.println(jsonResponse); // send message to server webSocket.sendTXT(jsonResponse); if(query == "cmd" || query == "?"){webSocket.sendTXT(jsonResponse);}
}
void getTemp(){
//Serial.print("Current humidity = ");
//Serial.print(dht.getHumidity());
//Serial.print("% ");
//Serial.print("temperature = ");
//Serial.print(dht.getTemperature());
//Serial.print("C ");
delay(800);
}
And my Alexa Skill
Intent :
smartsensorUtterances :
(German) : {query} ist die {Sensor_Values}
(English) : {query} is the {Sensor_Values}
- query (linked to query)
- Sensor Values (linked to measurement_tpye)
query: (German)
was
wiequery: (English)
howmeasurement_type: (German)
feuchtigkeit
temperaturmeasurement_type: (English)
temperature
from iot-smart-temperature-switch-with-alexa-nodemcu.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iot-smart-temperature-switch-with-alexa-nodemcu.