Lilygo-rtl_433 Build for Standalone Serial Mode over Builtin USB Port

I am looking to build opemqttgateway for lilygo-rtl_433 with the standalone serial mode that sends received data over serial without a MQTT broker. I was wondering if it is possible to send data over the builtin USB serial connection instead of GPIO pins so that I can connect it to a program running on a laptop. I haven’t had any luck with this so far. The log messages for the device itself show up in the console, but not any json data from 433mhz devices. The logs also show that serial is being initialized on UART 0, which should be the USB port on an ESP32. Here is what options I currently use to build.

I added this line to my build flags.

'-DZgatewaySERIAL="SERIAL"'

I also set DEFAULT_OFFLINE to true and DEFAULT_SERIAL to true in User_config.h and set SERIAL_UART to 0 and SERIALBaud to 115200 in config_SERIAL.h.

You should be able at least to use the logs output, by playing with the log level you would get less or more data (you don’t need gatewaySERIAL for this) :

This is not the most structured way of getting the data through Serial but it could work as a proof of concept.
I haven’t tried the gatewaySERIAL on the USB port, maybe something that we can look in the future.

In MQTT connected mode, it did give logs that I could parse in my program when in notice logging mode. However, in offline mode even with verbose logging, it did not give the decoded json.

T: isAdupl?
T: Enqueue JSON
T: Queue length: 1
T: Min ind: 4
T: store code : 47114 / 82827
T: Col: val/timestamp
T: mem code : 47114 / 8424
T: mem code : 10254 / 8495
T: mem code : 47114 / 44060
T: mem code : 95 / 58710
T: mem code : 47114 / 82827
T: mem code : 0 / 0
T: mem code : 0 / 0
T: mem code : 0 / 0
T: mem code : 0 / 0
T: mem code : 0 / 0
T: mem code : 0 / 0
T: mem code : 0 / 0
T: Dequeue JSON

I ended up adding this to the end of the enqueueJsonObject function so I could have this functionality in offline mode as well.

if (SYSConfig.offline){
  Log.notice(F("msg: %s" CR), jsonString.c_str());
}

I set the DEFAULT_SERIAL option to false, but left the DEFAULT_OFFLINE option set to true and removed the
‘-DZgatewaySERIAL=“SERIAL”’ build flag, then it was able to output the json messages in offline mode like it does in MQTT-connected mode.

N: msg: {"model":"Akhan-100F14","id":47114,"data":"0x8 (Alarm)","protocol":"Akhan 100F14 remote keyless entry","rssi":-45,"duration":119000,"origin":"/RTL_433toMQTT/Akhan-100F14/47114"}

Good catch!
I may ask you to do some test if we improve the RTL_433toSERIAL gateway

Sure, I can test any updated functionality for this feature.

@omgquestion, this look exactly what I’d like to do. Connect a Raspberry pi to a Lilygo and parse the rlt_433 messages without using an MQTT broker.

Would you mind summarising the steps required please? It looks like one code change, a rebuild and setting two options. Is that correct ?

You need to make a couple of minor changes to the User_config.h and main.ino files, then set whatever options you like in the prod_env.ini file as long as you include:

-DLOG_LEVEL=LOG_LEVEL_NOTICE

Then, you can build and flash using the platformio extension in vscode.

Here’s a git diff to better explain the changes I made to the code. I built from the v1.8.1 version tag.

diff --git a/main/User_config.h b/main/User_config.h
index c9793f4e..e8762839 100644
--- a/main/User_config.h
+++ b/main/User_config.h
@@ -678,16 +678,16 @@ struct SYSConfig_s {
 };
 
 #ifndef DEFAULT_MQTT
-#  define DEFAULT_MQTT true
+#  define DEFAULT_MQTT false
 #endif
 #ifndef DEFAULT_SERIAL
 #  define DEFAULT_SERIAL false
 #endif
 #ifndef DEFAULT_BLUFI
-#  define DEFAULT_BLUFI true
+#  define DEFAULT_BLUFI false
 #endif
 #ifndef DEFAULT_OFFLINE
-#  define DEFAULT_OFFLINE false
+#  define DEFAULT_OFFLINE true
 #endif
 
 #if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation) || defined(ZgatewayRTL_433)
diff --git a/main/main.ino b/main/main.ino
index 07b70eeb..4f7b3c4f 100644
--- a/main/main.ino
+++ b/main/main.ino
@@ -448,6 +448,9 @@ boolean enqueueJsonObject(const StaticJsonDocument<JSON_MSG_BUFFER>& jsonDoc, in
   xSemaphoreGive(xQueueMutex);
 #endif
   Log.trace(F("Queue length: %d" CR), jsonQueue.size());
+  if (SYSConfig.offline){
+    Log.notice(F("msg: %s" CR), jsonString.c_str());
+  }
   return true;
 }

And here is the prod_env.ini file that I used for the build.

[platformio]
default_envs = lilygo-rtl_433_custom

[env:lilygo-rtl_433_custom]
extends = env:lilygo-rtl_433
build_flags =
  ${env:lilygo-rtl_433.build_flags}
  '-DGateway_Name="gw433"'
  '-DLOG_LEVEL=LOG_LEVEL_NOTICE'
  '-UZwebUI'
  '-UZmqttDiscovery'
  '-UZdisplaySSD1306'

Thanks, I’m going to try it on the fsk version.