Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revisionLast revisionBoth sides next revision | ||
enocean [13.03.2018 07:56] – [add the async printer] Pascal Suter | enocean [16.03.2018 06:15] – [esp8266] Pascal Suter | ||
---|---|---|---|
Line 24: | Line 24: | ||
here are a few libraries i have found beforehand and intend on trying out: | here are a few libraries i have found beforehand and intend on trying out: | ||
* [[https:// | * [[https:// | ||
- | * [[https:// | + | * <del>[[https:// |
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
===== setup and development ===== | ===== setup and development ===== | ||
Line 61: | Line 63: | ||
</ | </ | ||
- | ==== add the async printer ==== | ||
- | we use [[https:// | ||
- | first we need to install | + | ==== add enOcean ==== |
- | cd <arduino directory>/ | + | now we can finally add the enocean receiver |
- | git clone https:// | + | |
- | for my development machine to receive those messages i need to open a socket with '' | + | next we need the [[http:// |
- | nc -l 3333 | + | |
- | and leave the terminal open. | + | |
- | now we could integrate it as is into our code as you can see in the example [[https:// | + | extract |
<code cpp> | <code cpp> | ||
- | while(_client->state() < 4) | + | #include < |
- | delay(1); | + | #include < |
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | bool enableOnlineDebugging=true; | ||
+ | const char *debuggerHost=" | ||
+ | |||
+ | EnOceanMsg _Msg; | ||
+ | AsyncPrinter ap; | ||
+ | WiFiManager wifiManager; | ||
+ | bool debugOnline=false; | ||
+ | bool firstround=true; | ||
+ | int lastPayload=0; | ||
+ | void setup() { | ||
+ | // put your setup code here, to run once: | ||
+ | Serial.begin(57600); | ||
+ | if(enableOnlineDebugging){ | ||
+ | wifiManager.setDebugOutput(false); | ||
+ | } | ||
+ | wifiManager.autoConnect(); | ||
+ | wifiManager.startWebPortal(); | ||
+ | ap.connect(debuggerHost, | ||
+ | if(enableOnlineDebugging){ | ||
+ | //block for maximum 5 seconds trying to reach the debugger | ||
+ | for ( int i = 0; i < 10 ; i++){ | ||
+ | | ||
+ | debugOnline=true; | ||
+ | ap.println(" | ||
+ | break; | ||
+ | } else { | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void debug(const char *message){ | ||
+ | if(debugOnline){ | ||
+ | ap.println(message); | ||
+ | } else { | ||
+ | Serial.println(" | ||
+ | } | ||
+ | _Msg.decode(); | ||
+ | if (_Msg.dataAvailable() == true){ | ||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
+ | void debugHex(int payload){ | ||
+ | if(debugOnline){ | ||
+ | ap.println(payload, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | void loop() { | ||
+ | // put your main code here, to run repeatedly: | ||
+ | int payload=0; | ||
+ | wifiManager.process(); | ||
+ | if(firstround){ | ||
+ | debug(" | ||
+ | firstround=false; | ||
+ | } | ||
+ | _Msg.decode(); | ||
+ | if(_Msg.dataAvailable() == true){ | ||
+ | payload=_Msg.getPayload(); | ||
+ | if(payload!=lastPayload){ | ||
+ | debug(" | ||
+ | debugHex(payload); | ||
+ | lastPayload=payload; | ||
+ | debugHex(_Msg.getSenderId()); | ||
+ | } | ||
+ | } | ||
+ | delay(50); | ||
+ | } | ||
</ | </ | ||
+ | now you should see output like this on your netcat console after you started the sketch and then pressed a button: | ||
+ | < | ||
+ | connected | ||
+ | hello world | ||
+ | new payload received: | ||
+ | 70 | ||
+ | 3102F7 | ||
+ | new payload received: | ||
+ | 0 | ||
+ | 3102F7 | ||
+ | </ | ||
+ | '' | ||
+ | |||
+ | ==== MQTT ==== | ||
+ | next up is MQTT support throught he [[https:// | ||
+ | |||
+ | download the [[https:// | ||
- | let's add '' | + | this is just a copy paste of a code that somewhat worked.. before i clean it out and re-post here |
<code cpp> | <code cpp> | ||
Line 86: | Line 176: | ||
#include < | #include < | ||
#include < | #include < | ||
+ | #include < | ||
+ | #include < | ||
bool enableOnlineDebugging=true; | bool enableOnlineDebugging=true; | ||
const char *debuggerHost=" | const char *debuggerHost=" | ||
+ | const char *mqttServer=" | ||
+ | int mqttPort=1883; | ||
+ | EnOceanMsg _Msg; | ||
AsyncPrinter ap; | AsyncPrinter ap; | ||
WiFiManager wifiManager; | WiFiManager wifiManager; | ||
bool debugOnline=false; | bool debugOnline=false; | ||
bool firstround=true; | bool firstround=true; | ||
+ | int lastPayload=0; | ||
+ | AsyncMqttClient mqtt; | ||
+ | bool mqttConnected=false; | ||
+ | String mqttBaseTopic=" | ||
+ | |||
+ | void onMqttConnect(bool sessionPresent){ | ||
+ | debug(" | ||
+ | mqttConnected=true; | ||
+ | } | ||
void setup() { | void setup() { | ||
// put your setup code here, to run once: | // put your setup code here, to run once: | ||
- | Serial.begin(115200); | + | Serial.begin(57600); |
+ | if(enableOnlineDebugging){ | ||
+ | wifiManager.setDebugOutput(false); | ||
+ | } | ||
wifiManager.autoConnect(); | wifiManager.autoConnect(); | ||
wifiManager.startWebPortal(); | wifiManager.startWebPortal(); | ||
ap.connect(debuggerHost, | ap.connect(debuggerHost, | ||
+ | mqtt.setServer(mqttServer, | ||
+ | mqtt.onConnect(onMqttConnect); | ||
if(enableOnlineDebugging){ | if(enableOnlineDebugging){ | ||
//block for maximum 5 seconds trying to reach the debugger | //block for maximum 5 seconds trying to reach the debugger | ||
Line 106: | Line 215: | ||
if(ap.connected()){ | if(ap.connected()){ | ||
debugOnline=true; | debugOnline=true; | ||
- | ap.println(" | + | ap.println(" |
+ | debug(" | ||
+ | mqtt.connect(); | ||
break; | break; | ||
} else { | } else { | ||
Line 120: | Line 231: | ||
} else { | } else { | ||
Serial.println(" | Serial.println(" | ||
+ | } | ||
+ | _Msg.decode(); | ||
+ | if (_Msg.dataAvailable() == true){ | ||
+ | | ||
} | } | ||
} | } | ||
+ | |||
+ | void debugHex(int payload){ | ||
+ | if(debugOnline){ | ||
+ | ap.println(payload, | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
void loop() { | void loop() { | ||
// put your main code here, to run repeatedly: | // put your main code here, to run repeatedly: | ||
+ | int payload=0; | ||
+ | uint32_t senderId=0; | ||
+ | char * topic; | ||
+ | | ||
wifiManager.process(); | wifiManager.process(); | ||
if(firstround){ | if(firstround){ | ||
Line 129: | Line 256: | ||
firstround=false; | firstround=false; | ||
} | } | ||
+ | _Msg.decode(); | ||
+ | if(_Msg.dataAvailable() == true){ | ||
+ | payload=_Msg.getPayload(); | ||
+ | if(payload!=lastPayload){ | ||
+ | debug(" | ||
+ | debugHex(payload); | ||
+ | lastPayload=payload; | ||
+ | senderId=_Msg.getSenderId(); | ||
+ | debugHex(senderId); | ||
+ | if(payload > 0 && senderId > 0 && mqttConnected){ | ||
+ | //String t = String(mqttBaseTopic+"/" | ||
+ | //char topic[sizeof(t)]; | ||
+ | // | ||
+ | debug(" | ||
+ | uint16_t packetIdPub1 = mqtt.publish(" | ||
+ | } else { | ||
+ | debug(" | ||
+ | uint16_t packetIdPub1 = mqtt.publish(" | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | delay(50); | ||
} | } | ||
</ | </ | ||
- | you should now see "setup done" and "hello world" on your terminal with '' |