Initial WIP 2
This commit is contained in:
parent
5a7ace4af4
commit
4867d92b62
@ -1,5 +1,6 @@
|
|||||||
[env:KnxEsp]
|
[env:KnxEsp]
|
||||||
platform = espressif32
|
platform = espressif8266
|
||||||
board = esp32dev
|
board = esp12e
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps = https://github.com/thorsten-gehrig/arduino-tpuart-knx-user-forum
|
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 <Arduino.h>
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
#include <KnxTpUart.h>
|
#include <KnxTpUart.h>
|
||||||
|
#include <PubSubClient.h>
|
||||||
#include "Group.h"
|
|
||||||
|
|
||||||
KnxTpUart knx(&Serial1, "15.15.20");
|
KnxTpUart knx(&Serial1, "15.15.20");
|
||||||
|
|
||||||
|
PubSubClient mqtt;
|
||||||
|
|
||||||
void knxSetup();
|
void knxSetup();
|
||||||
|
|
||||||
void knxLoop();
|
void knxLoop();
|
||||||
|
|
||||||
|
void mqttLoop();
|
||||||
|
|
||||||
|
void mqttSetup();
|
||||||
|
|
||||||
|
void wifiSetup();
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(112500);
|
Serial.begin(112500);
|
||||||
delay(500);
|
delay(500);
|
||||||
Serial.print("\n\n\nStartup\n");
|
Serial.print("\n\n\nStartup\n");
|
||||||
knxSetup();
|
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() {
|
void loop() {
|
||||||
knxLoop();
|
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() {
|
void knxSetup() {
|
||||||
@ -32,7 +65,6 @@ void knxLoop() {
|
|||||||
if (type != KNX_TELEGRAM) {
|
if (type != KNX_TELEGRAM) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
KnxTelegram *telegram = knx.getReceivedTelegram();
|
KnxTelegram *t = knx.getReceivedTelegram();
|
||||||
Group::write(telegram->getTargetMainGroup(), telegram->getTargetMiddleGroup(), telegram->getTargetSubGroup(),telegram->getPayloadLength());
|
Serial.printf("%3d / %3d / %3d len=%d, bool=%d\n", t->getTargetMainGroup(), t->getTargetMiddleGroup(), t->getTargetSubGroup(), t->getPayloadLength(), t->getBool());
|
||||||
Serial.printf("%d/%d/%d\n", telegram->getTargetMainGroup(), telegram->getTargetMiddleGroup(), telegram->getTargetSubGroup());
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user