mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-08 22:22:05 +00:00
Merge pull request #1165 from joshpirihi/master
Allow publishing of decrypted packets to MQTT
This commit is contained in:
commit
e4fe2c159a
@ -210,6 +210,33 @@ ErrorCode Router::send(MeshPacket *p)
|
|||||||
if (p->which_payloadVariant == MeshPacket_decoded_tag) {
|
if (p->which_payloadVariant == MeshPacket_decoded_tag) {
|
||||||
ChannelIndex chIndex = p->channel; // keep as a local because we are about to change it
|
ChannelIndex chIndex = p->channel; // keep as a local because we are about to change it
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if defined(HAS_WIFI) || defined(PORTDUINO)
|
||||||
|
//check if we should send decrypted packets to mqtt
|
||||||
|
|
||||||
|
//truth table:
|
||||||
|
/* mqtt_server mqtt_encryption_enabled should_encrypt
|
||||||
|
* not set 0 1
|
||||||
|
* not set 1 1
|
||||||
|
* set 0 0
|
||||||
|
* set 1 1
|
||||||
|
*
|
||||||
|
* => so we only decrypt mqtt if they have a custom mqtt server AND mqtt_encryption_enabled is FALSE
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool shouldActuallyEncrypt = true;
|
||||||
|
if (*radioConfig.preferences.mqtt_server && !radioConfig.preferences.mqtt_encryption_enabled) {
|
||||||
|
shouldActuallyEncrypt = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_MSG("Should encrypt MQTT?: %d\n", shouldActuallyEncrypt);
|
||||||
|
|
||||||
|
//the packet is currently in a decrypted state. send it now if they want decrypted packets
|
||||||
|
if (mqtt && !shouldActuallyEncrypt)
|
||||||
|
mqtt->onSend(*p, chIndex);
|
||||||
|
#endif
|
||||||
|
|
||||||
auto encodeResult = perhapsEncode(p);
|
auto encodeResult = perhapsEncode(p);
|
||||||
if (encodeResult != Routing_Error_NONE) {
|
if (encodeResult != Routing_Error_NONE) {
|
||||||
abortSendAndNak(encodeResult, p);
|
abortSendAndNak(encodeResult, p);
|
||||||
@ -217,7 +244,9 @@ ErrorCode Router::send(MeshPacket *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(HAS_WIFI) || defined(PORTDUINO)
|
#if defined(HAS_WIFI) || defined(PORTDUINO)
|
||||||
if (mqtt)
|
//the packet is now encrypted.
|
||||||
|
//check if we should send encrypted packets to mqtt
|
||||||
|
if (mqtt && shouldActuallyEncrypt)
|
||||||
mqtt->onSend(*p, chIndex);
|
mqtt->onSend(*p, chIndex);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user