Initial WIP 2
This commit is contained in:
parent
5a7ace4af4
commit
4867d92b62
@ -1,5 +1,6 @@
|
||||
[env:KnxEsp]
|
||||
platform = espressif32
|
||||
board = esp32dev
|
||||
platform = espressif8266
|
||||
board = esp12e
|
||||
framework = arduino
|
||||
lib_deps = https://github.com/thorsten-gehrig/arduino-tpuart-knx-user-forum
|
||||
https://github.com/knolleary/pubsubclient
|
||||
|
||||
44
src/main.cpp
44
src/main.cpp
@ -1,24 +1,57 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <KnxTpUart.h>
|
||||
|
||||
#include "Group.h"
|
||||
#include <PubSubClient.h>
|
||||
|
||||
KnxTpUart knx(&Serial1, "15.15.20");
|
||||
|
||||
PubSubClient mqtt;
|
||||
|
||||
void knxSetup();
|
||||
|
||||
void knxLoop();
|
||||
|
||||
void mqttLoop();
|
||||
|
||||
void mqttSetup();
|
||||
|
||||
void wifiSetup();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(112500);
|
||||
delay(500);
|
||||
Serial.print("\n\n\nStartup\n");
|
||||
knxSetup();
|
||||
wifiSetup();
|
||||
configTime("Europe/Berlin", "de.pool.ntp.org");
|
||||
mqttSetup();
|
||||
}
|
||||
|
||||
void wifiSetup() {
|
||||
WiFi.hostname("KnxEsp");
|
||||
WiFi.begin("HappyNet", "1Grausame!Sackratte7");
|
||||
while (WiFi.localIP() == 0UL) {
|
||||
delay(100);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
knxLoop();
|
||||
mqttLoop();
|
||||
}
|
||||
|
||||
void mqttSetup() {
|
||||
mqtt.setServer("10.0.0.50", 1883);
|
||||
mqtt.setBufferSize(512);
|
||||
}
|
||||
|
||||
void mqttLoop() {
|
||||
if (!mqtt.loop()) {
|
||||
if (!mqtt.connect(WiFi.hostname().c_str())) {
|
||||
mqtt.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void knxSetup() {
|
||||
@ -32,7 +65,6 @@ void knxLoop() {
|
||||
if (type != KNX_TELEGRAM) {
|
||||
return;
|
||||
}
|
||||
KnxTelegram *telegram = knx.getReceivedTelegram();
|
||||
Group::write(telegram->getTargetMainGroup(), telegram->getTargetMiddleGroup(), telegram->getTargetSubGroup(),telegram->getPayloadLength());
|
||||
Serial.printf("%d/%d/%d\n", telegram->getTargetMainGroup(), telegram->getTargetMiddleGroup(), telegram->getTargetSubGroup());
|
||||
KnxTelegram *t = knx.getReceivedTelegram();
|
||||
Serial.printf("%3d / %3d / %3d len=%d, bool=%d\n", t->getTargetMainGroup(), t->getTargetMiddleGroup(), t->getTargetSubGroup(), t->getPayloadLength(), t->getBool());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user