Publish blind position to MQTT when packet is received
This commit is contained in:
@@ -29,3 +29,5 @@ lib_deps =
|
||||
PacketCRC=symlink://..\PowerViewSniffer\lib\PacketCRC
|
||||
|
||||
PacketBuilder
|
||||
|
||||
PacketParser=symlink://..\PowerViewSniffer\lib\PacketParser
|
||||
|
||||
21
src/main.cpp
21
src/main.cpp
@@ -7,6 +7,7 @@
|
||||
#include <EspMQTTClient.h>
|
||||
#include <PacketReceiver.h>
|
||||
#include <PacketBuilder.h>
|
||||
#include <PacketParser.h>
|
||||
#include "secrets.h"
|
||||
|
||||
#define SER_BAUDRATE (115200)
|
||||
@@ -22,6 +23,7 @@ static const uint8_t rfID[2] = { 0xC8, 0x2E }; // 0x2EC8
|
||||
PacketReceiver packetReceiver(&radio);
|
||||
PacketBuilder remotePacketBuilder(0x369E, 0xAC, 0x82, 0x06);
|
||||
PacketBuilder hubPacketBuilder(0x0000, 0x3D, 0x96, 0x05);
|
||||
PacketParser packetParser;
|
||||
|
||||
EspMQTTClient client(
|
||||
SECRET_WIFI_SSID, // Wifi SSID
|
||||
@@ -115,7 +117,24 @@ void radioTransmitSetup() {
|
||||
}
|
||||
|
||||
void processPacket(const uint8_t *buffer) {
|
||||
Serial.println("Got packet");
|
||||
Message message;
|
||||
bool result = packetParser.parsePacket(buffer, message);
|
||||
if (result) {
|
||||
if (message.type == PacketType::PUBLISH_FIELDS) {
|
||||
PublishFieldsParameters parameters = std::get<PublishFieldsParameters>(message.parameters);
|
||||
for (size_t i = 0; i < parameters.fields.size(); i++) {
|
||||
Field field = parameters.fields[i];
|
||||
if (field.identifier == 0x50) {
|
||||
if (message.source == 0x4EF1) {
|
||||
uint16_t value = std::get<uint16_t>(field.value);
|
||||
uint8_t position = (uint8_t)std::round(((float)value / 0xFFFF) * 100);
|
||||
String payload = String(position);
|
||||
client.publish("hotdog/test_mqtt_blind/position", payload, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sendCommand(uint8_t *buffer) //transmit a command
|
||||
|
||||
Reference in New Issue
Block a user