enocean

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
enocean [16.03.2018 05:42] – [esp8266] Pascal Suterenocean [16.03.2018 06:05] – [esp8266] Pascal Suter
Line 27: Line 27:
   * [[https://github.com/tzapu/WiFiManager|WiFiManager]] seems to do all we need to make the final device easy to get configured without a serial connection (has automatic fall back to AP mode with captive portal config page).    * [[https://github.com/tzapu/WiFiManager|WiFiManager]] seems to do all we need to make the final device easy to get configured without a serial connection (has automatic fall back to AP mode with captive portal config page). 
   * [[https://bitbucket.org/charly37/arduino_enocean_lib/downloads/|arduino enocean library]] with a [[http://djynet.net/?p=635|description from the developer]]   * [[https://bitbucket.org/charly37/arduino_enocean_lib/downloads/|arduino enocean library]] with a [[http://djynet.net/?p=635|description from the developer]]
 +  * [[https://github.com/KoljaWindeler/ESP8266_mqtt_pwm_pir_temp/tree/master/JKW_MQTT_PWM_PIR_TEMP/src|a similar project]] i found only after starting this. maybe i could just expand that one rather than writing my own? a shame i found it so late. 
  
 ===== setup and development ===== ===== setup and development =====
Line 167: Line 168:
 download the [[https://github.com/marvinroger/async-mqtt-client/releases|latest release]] as zip file and then add it via Sketch->Include Library->Add .ZIP library download the [[https://github.com/marvinroger/async-mqtt-client/releases|latest release]] as zip file and then add it via Sketch->Include Library->Add .ZIP library
  
 +this is just a copy paste of a code that somewhat worked.. before i clean it out and re-post here
  
 +<code cpp>
 +#include <ESP8266WiFi.h>          //ESP8266 Core WiFi Library (you most likely already have this in your sketch)
 +#include <DNSServer.h>            //Local DNS Server used for redirecting all requests to the configuration portal
 +#include <ESP8266WebServer.h>     //Local WebServer used to serve the configuration portal
 +#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
 +#include <AsyncPrinter.h>
 +#include <EnOceanMsg.h>           //http://djynet.net/?p=635
 +#include <AsyncMqttClient.h>       //https://github.com/marvinroger/async-mqtt-client
  
 +bool enableOnlineDebugging=true;
 +const char *debuggerHost="192.168.168.48";
 +const char *mqttServer="192.168.168.1";
 +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="enOcean";
 +
 +void onMqttConnect(bool sessionPresent){
 +  debug("connected to mqtt server");
 +  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,3333);
 +  mqtt.setServer(mqttServer,mqttPort);
 +  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("connected");
 +        debug("initiate mqtt connection");
 +        mqtt.connect();
 +        break;
 +      } else {
 +        delay(500);
 +      }
 +    }
 +  }
 +}
 +
 +void debug(const char *message){
 +  if(debugOnline){
 +    ap.println(message);
 +  } else {
 +    Serial.println("debugger is not online");
 +  }
 +  _Msg.decode();
 +  if (_Msg.dataAvailable() == true){
 +    
 +  }
 +}
 +
 +void debugHex(int payload){
 +  if(debugOnline){
 +    ap.println(payload,HEX);
 +  }  
 +}
 +
 +
 +void loop() {
 +  // put your main code here, to run repeatedly:
 +  int payload=0;
 +  uint32_t senderId=0;
 +  char * topic;
 +  
 +  wifiManager.process();
 +  if(firstround){
 +    debug("hello world");
 +    firstround=false;
 +  }
 +  _Msg.decode();
 +  if(_Msg.dataAvailable() == true){
 +    payload=_Msg.getPayload();
 +    if(payload!=lastPayload){
 +      debug("new payload received:");
 +      debugHex(payload);
 +      lastPayload=payload;
 +      senderId=_Msg.getSenderId();
 +      debugHex(senderId);
 +      if(payload > 0 && senderId > 0 && mqttConnected){
 +        //String t = String(mqttBaseTopic+"/"+senderId+"/"+payload);
 +        //char topic[sizeof(t)];
 +        //t.toCharArray(topic,sizeof(topic));
 +        debug("publish ON message");
 +        uint16_t packetIdPub1 = mqtt.publish("enocean/button", 1, true, "ON");
 +      } else {
 +        debug("publish OFF message");
 +        uint16_t packetIdPub1 = mqtt.publish("enocean/button", 1, true, "OFF");
 +      }
 +    }
 +  }
 +  delay(50);
 +}
 +</code>
  • enocean.txt
  • Last modified: 16.03.2018 06:18
  • by Pascal Suter