fix #2109 json mqtt on secondary channel

This commit is contained in:
Thomas Göttgens 2023-01-23 21:29:46 +01:00
parent 083dcef9d6
commit 81854a173a
2 changed files with 7 additions and 8 deletions

View File

@ -2,8 +2,9 @@
// See http://go.microsoft.com/fwlink/?LinkId=827846 // See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format // for the documentation about the extensions.json format
"recommendations": [ "recommendations": [
"ms-vscode.cpptools", "platformio.platformio-ide"
"platformio.platformio-ide",
"trunk.io"
], ],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
} }

View File

@ -53,10 +53,8 @@ void MQTT::onPublish(char *topic, byte *payload, unsigned int length)
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
ptr = strtok(NULL, "/"); ptr = strtok(NULL, "/");
} }
LOG_DEBUG("Looking for Channel name: %s\n", ptr);
meshtastic_Channel sendChannel = channels.getByName(ptr); meshtastic_Channel sendChannel = channels.getByName(ptr);
LOG_DEBUG("Found Channel name: %s (Index %d)\n", channels.getGlobalId(sendChannel.settings.channel_num), LOG_DEBUG("Found Channel name: %s (Index %d)\n", channels.getGlobalId(sendChannel.index), sendChannel.index);
sendChannel.settings.channel_num);
if ((json.find("sender") != json.end()) && (json.find("payload") != json.end()) && if ((json.find("sender") != json.end()) && (json.find("payload") != json.end()) &&
(json.find("type") != json.end()) && json["type"]->IsString() && (json.find("type") != json.end()) && json["type"]->IsString() &&
@ -70,7 +68,7 @@ void MQTT::onPublish(char *topic, byte *payload, unsigned int length)
// construct protobuf data packet using TEXT_MESSAGE, send it to the mesh // construct protobuf data packet using TEXT_MESSAGE, send it to the mesh
meshtastic_MeshPacket *p = router->allocForSending(); meshtastic_MeshPacket *p = router->allocForSending();
p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP; p->decoded.portnum = meshtastic_PortNum_TEXT_MESSAGE_APP;
p->channel = sendChannel.settings.channel_num; p->channel = sendChannel.index;
if (sendChannel.settings.downlink_enabled) { if (sendChannel.settings.downlink_enabled) {
if (jsonPayloadStr.length() <= sizeof(p->decoded.payload.bytes)) { if (jsonPayloadStr.length() <= sizeof(p->decoded.payload.bytes)) {
memcpy(p->decoded.payload.bytes, jsonPayloadStr.c_str(), jsonPayloadStr.length()); memcpy(p->decoded.payload.bytes, jsonPayloadStr.c_str(), jsonPayloadStr.length());
@ -104,7 +102,7 @@ void MQTT::onPublish(char *topic, byte *payload, unsigned int length)
// construct protobuf data packet using POSITION, send it to the mesh // construct protobuf data packet using POSITION, send it to the mesh
meshtastic_MeshPacket *p = router->allocForSending(); meshtastic_MeshPacket *p = router->allocForSending();
p->decoded.portnum = meshtastic_PortNum_POSITION_APP; p->decoded.portnum = meshtastic_PortNum_POSITION_APP;
p->channel = sendChannel.settings.channel_num; p->channel = sendChannel.index;
if (sendChannel.settings.downlink_enabled) { if (sendChannel.settings.downlink_enabled) {
p->decoded.payload.size = p->decoded.payload.size =
pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes),