Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add JSON parsing and hardware serial support to RS232 gateway #1409

Merged
merged 12 commits into from
Jan 25, 2023

Conversation

mreijnde
Copy link
Contributor

@mreijnde mreijnde commented Jan 21, 2023

Description:

I added some features to the RS232 gateway I like to share. My use-case is logging JSON data to MQTT generated by an other microprocessor through a serial connection to OMG running on a ESP8266 or ESP32.

Improvements:

  • support for hardware serial (instead of software serial) to support higher baud rates
  • support parsing of JSON received on the serial link to separate data in MQTT (sub) topics based on the JSON keys (up to the given nesting level).

EXAMPLE:
retrieved data on serial link: "{temperature: {sens1: 22, sens2: 23}, humidity: {sens1: 80, sens2: 60}}"

output to MQTT ( RS232maxJSONlevel=1):
./RS232toMQTT/temperature ==> "{sens1: 22, sens2: 23}"
./RS232toMQTT/humidity ==> "{sens1: 80, sens2: 60}"

output to MQTT ( RS232maxJSONlevel=2 (or higher)):
./RS232toMQTT/temperature/sens1 ==> 22
./RS232toMQTT/temperature/sens2 ==> 23
./RS232toMQTT/humidity/sens1 ==> 80
./RS232toMQTT/humidity/sens2 ==> 60

As default the original behavior is enabled to send the full RS232 like as MQTT message. By setting the RS232toMQTTmode to 1, the new JSON parsing mode can be enabled.

I tested it on a ESP32 and a ESP8266. The original 'raw' mode compiles on a Arduino Uno, the JSON variant does not fit in flash. The Arduino Mega does not compile, like on the original branch. I removed reference to it in the update.

Please have a look , I am open to suggestions to improve.

Checklist:

  • The pull request is done against the latest development branch
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • I accept the DCO.

@1technophile
Copy link
Owner

@DieKatzchen would it be possible to review this PR as you are the author of the first version ?

@DieKatzchen
Copy link
Contributor

DieKatzchen commented Jan 23, 2023

Gave it a look over, only thing I would change is putting the SoftwareSerial #include inside the #ifndef, since we wouldn't be using it in that instance. The serial stuff all looks about right (actually, I learned a thing or two), and I can't comment on the JSON formatting.

@1technophile
Copy link
Owner

@mreijnde Thanks for the PR, could you take into account the comment please

@mreijnde
Copy link
Contributor Author

I moved the #include as requested.

Furthermore:

  • I added short explanation to the RS232 document
  • Reverted the commit that removed pin config for Arduino Mega. Compile error earlier was due a misconfiguration.

@1technophile
Copy link
Owner

Thanks!

@1technophile 1technophile merged commit 6e3e8c3 into 1technophile:development Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants