Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
enocean [10.03.2018 04:55] – [get wifimanager to work] Pascal Suter | enocean [16.03.2018 05:45] – [MQTT] Pascal Suter | ||
---|---|---|---|
Line 13: | Line 13: | ||
{{:: | {{:: | ||
- | thanks to [[http:// | + | thanks to [[http:// |
+ | > The IOVdd and Vdd pins are connected directly to pin 1 (3.3V) on Raspberry Pi. Besides the power and ground pins, the only connections are to the hardware UART pins (header pin 8 and pin 10). | ||
===== esp8266 ===== | ===== esp8266 ===== | ||
I plan on using a Wemos D1 mini module (or a clone of it i guess) which can be purchased on aliexpress for a few $. i will then use the arduino core on it to program it via the arduino IDE. | I plan on using a Wemos D1 mini module (or a clone of it i guess) which can be purchased on aliexpress for a few $. i will then use the arduino core on it to program it via the arduino IDE. | ||
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:// | + | * [[https:// |
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
===== setup and development ===== | ===== setup and development ===== | ||
Line 58: | Line 59: | ||
// put your main code here, to run repeatedly: | // put your main code here, to run repeatedly: | ||
wifiManager.process(); | wifiManager.process(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== add enOcean ==== | ||
+ | now we can finally add the enocean receiver to our setup. we therefore connect the +3.3V to the +3.3V of the Wemos D1, the GND to the GND and we cross connect the RX of the enocean Module to the TX of the Wemos D1 and the same for the TX fo the enOcean that goes to the RX of the Wemos | ||
+ | |||
+ | next we need the [[http:// | ||
+ | |||
+ | extract the contents of this ZIP to the '' | ||
+ | <code cpp> | ||
+ | #include < | ||
+ | #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++){ | ||
+ | if(ap.connected()){ | ||
+ | debugOnline=true; | ||
+ | ap.println(" | ||
+ | break; | ||
+ | } else { | ||
+ | delay(500); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | 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:// | ||
+ | |||
+ | this is just a copy paste of a code that somewhat worked.. before i clean it out and re-post here | ||
+ | |||
+ | <code cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | bool enableOnlineDebugging=true; | ||
+ | const char *debuggerHost=" | ||
+ | const char *mqttServer=" | ||
+ | int mqttPort=1883; | ||
+ | |||
+ | EnOceanMsg _Msg; | ||
+ | AsyncPrinter ap; | ||
+ | WiFiManager wifiManager; | ||
+ | bool debugOnline=false; | ||
+ | bool firstround=true; | ||
+ | int lastPayload=0; | ||
+ | AsyncMqttClient mqtt; | ||
+ | bool mqttConnected=false; | ||
+ | String mqttBaseTopic=" | ||
+ | |||
+ | void onMqttConnect(bool sessionPresent){ | ||
+ | debug(" | ||
+ | mqttConnected=true; | ||
+ | } | ||
+ | |||
+ | 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, | ||
+ | mqtt.setServer(mqttServer, | ||
+ | mqtt.onConnect(onMqttConnect); | ||
+ | if(enableOnlineDebugging){ | ||
+ | //block for maximum 5 seconds trying to reach the debugger | ||
+ | for ( int i = 0; i < 10 ; i++){ | ||
+ | if(ap.connected()){ | ||
+ | debugOnline=true; | ||
+ | ap.println(" | ||
+ | debug(" | ||
+ | mqtt.connect(); | ||
+ | break; | ||
+ | } else { | ||
+ | delay(500); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | 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; | ||
+ | uint32_t senderId=0; | ||
+ | char * topic; | ||
+ | | ||
+ | wifiManager.process(); | ||
+ | if(firstround){ | ||
+ | debug(" | ||
+ | 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); | ||
} | } | ||
</ | </ |