Serial output directly into NodeRED

Related to the the forum.
Post Reply
mrburnette
Posts: 410
Joined: Thu Dec 19, 2019 1:23 am
Answers: 1

Serial output directly into NodeRED

Post by mrburnette »

A few years back, a friend with an Arduino engine monitor that drives in cockpit OLED displays for various Rotax sensors decided he wanted to be able to have graphical gauges on a larger tablet-size device. The Arduino software design was old, 2013'ish design on a Mega2560... just not enough resources to drive a graphical display without significant redesign which was of no interest to my pilot friend.

After some research, I found this article:
https://groups.google.com/g/node-red/c/pvY36rlRUdI

Essentially, what the article is saying is that you can format a serial output stream in a rather simple manner and directly import that serial into any PC (via serial or serial-USB or Bluetooth serial) and NodeRED has serial "connectors" that can process the serial stream. Items in the stream can be parsed easily and then attached to a variety of gauges or graphs.

The Rotax engine monitor already had a serial debug stream! All that had to be done to make this NodeRED compatible was just some edits to the debug functions that did the serial printing. So easy!

Here is some code to show how easy it was:
Note that the prefix "{" and suffix "}" that closes the JSON are hardcoded. This was just being lazy on my part :o
Because of the hardcoding, analog_0() must be called first and thermo11() must be called last.
To test you formatting, capture data to a text file and copy & paste output here: https://jsonlint.com/

Code: Select all

void loop() {
    analog_0();           // A0  Water temperature
    analog_1();           // A1  Oil temperature
    analog_2();           // A2  Oil Pressure
    analog_10();          // A10 Amps measured
    analog_12();          // A12 Battery voltage measured        
    analog_15();          // A15 Fuel pressure

    thermo_0();           //     Exhaust Gas left
    thermo_1();           // To be determined   ... uncomment function in JSON tab
    thermo_2();           // To be determined
    thermo_3();           // To be determined
    thermo_4();           // To be determined
    thermo_5();           // To be determined
    thermo_6();           // To be determined
    thermo_7();           // To be determined
    thermo_8();           // To be determined
    thermo_9();           // To be determined
    thermo_10();          // To be determined
    thermo_11();          // To be determined
    delay(5000);

}
And the output stream:

Code: Select all

/* Faux JSON file format https://groups.google.com/forum/#!topic/node-red/pvY36rlRUdI */

void analog_0(void) {
  float temp = EngineCoolantTemp();
  Serial.print("{\"H2O_Tmp\":"); Serial.print(temp);  Serial.print (",");
}

void analog_1(void) {                                   /* Oil temperature */
  float temp  = float(EngOilTemp() );
  Serial.print ("\"Oil_Tmp\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void analog_2(void) {                                   /* Engine Oil Pressure */
  float temp = float (EngineOilPres());
  Serial.print("\"Oil_Prs\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void analog_10(void) {                                  /* Amps measured */
  float temp = float (BatteryAmps());
  Serial.print("\"Current\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void analog_12(void) {                                   /* Battery voltage measured */
  float temp = float (BatteryVoltage());
  Serial.print("\"Voltage\":"); Serial.print(temp);  Serial.print(",");
  return;
}
void analog_15(void) {                                   /* Gasoline fuel pressure */
  float temp = fuelPressure();                                        /* fuel pressure is a fp math function */
  Serial.print("\"Gas_Prs\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void thermo_0(void) {                                  /* Exhaust Gas left */
  int temp  = float (thermocouple_channel( 0));
  Serial.print("\"EGT_1\":"); Serial.print(temp);  Serial.print(",");
  return;
}


void thermo_1(void) {
  int temp  = float (thermocouple_channel( 1));
  Serial.print("\"EGT_2\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void thermo_2(void) {
  int temp  = float (thermocouple_channel( 2));
  Serial.print("\"EGT_3\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void thermo_3(void) {
  int temp  = float (thermocouple_channel( 3));
  Serial.print("\"EGT_4\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void thermo_4(void) {
  int temp  = float (thermocouple_channel( 4));
  Serial.print("\"EGT_5\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void thermo_5(void) {
  int temp  = float (thermocouple_channel( 5));
  Serial.print("\"EGT_6\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void thermo_6(void) {
  int temp  = float (thermocouple_channel( 6));
  Serial.print("\"EGT_7\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void thermo_7(void) {
  int temp  = float (thermocouple_channel( 7));
  Serial.print("\"EGT_8\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void thermo_8(void) {
  int temp  = float (thermocouple_channel( 8));
  Serial.print("\"EGT_9\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void thermo_9(void) {
  int temp  = float (thermocouple_channel( 9));
  Serial.print("\"EGT_10\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void thermo_10(void) {
  int temp  = float (thermocouple_channel(10));
  Serial.print("\"EGT_11\":"); Serial.print(temp);  Serial.print(",");
  return;
}

void thermo_11(void) {
  int temp  = float (thermocouple_channel(11));
  Serial.print("\"EGT_12\":"); Serial.print(temp);  Serial.print("}\n");
  return;
}

Last edited by mrburnette on Wed Mar 10, 2021 5:12 pm, edited 1 time in total.
mrburnette
Posts: 410
Joined: Thu Dec 19, 2019 1:23 am
Answers: 1

Re: Serial output directly into NodeRED

Post by mrburnette »

Only Parse what you want from the JSON serial stream ...
(Also you can do some rather sophisticated math within NodeRED)
NodeRedTest.png
NodeRedTest.png (34.49 KiB) Viewed 1483 times
Portion Screenshot from 2019-09-26 11-16-41.jpg
Portion Screenshot from 2019-09-26 11-16-41.jpg (56.6 KiB) Viewed 1482 times
Last edited by mrburnette on Wed Mar 10, 2021 5:32 pm, edited 2 times in total.
mrburnette
Posts: 410
Joined: Thu Dec 19, 2019 1:23 am
Answers: 1

Re: Serial output directly into NodeRED

Post by mrburnette »

Even on an rPi Zero-W, resources are not exhausted:

NodeRed_Europa.jpg
NodeRed_Europa.jpg (83.69 KiB) Viewed 1475 times
(disregard the "RPi3B" in graph title ... mislabeled from a previous test.)
Node-Red on rPi Zero-W.jpg
Node-Red on rPi Zero-W.jpg (88.52 KiB) Viewed 1472 times
Unless the rPi-Zero-W is required for the small footprint, the rPi-4B with 2G - 4G of RAM is the sweet point for the NodeRED server:
rpi4B_htop.jpg
rpi4B_htop.jpg (77.87 KiB) Viewed 1465 times
Last edited by mrburnette on Wed Mar 10, 2021 8:45 pm, edited 2 times in total.
mrburnette
Posts: 410
Joined: Thu Dec 19, 2019 1:23 am
Answers: 1

Re: Serial output directly into NodeRED

Post by mrburnette »

JSON node and properties
Screenshot from 2019-10-23 16-23-38.png
Screenshot from 2019-10-23 16-23-38.png (17.21 KiB) Viewed 1463 times

Function node and properties
Screenshot from 2019-10-23 16-26-39.png
Screenshot from 2019-10-23 16-26-39.png (17.32 KiB) Viewed 1463 times

Mapping ranges to colors
Screenshot from 2019-10-23 16-30-03.png
Screenshot from 2019-10-23 16-30-03.png (31.64 KiB) Viewed 1463 times
Last edited by mrburnette on Wed Mar 10, 2021 8:47 pm, edited 2 times in total.
mrburnette
Posts: 410
Joined: Thu Dec 19, 2019 1:23 am
Answers: 1

Re: Serial output directly into NodeRED

Post by mrburnette »

Layout

Screenshot from 2019-10-23 16-32-56.png
Screenshot from 2019-10-23 16-32-56.png (29.46 KiB) Viewed 1462 times
Last edited by mrburnette on Wed Mar 10, 2021 8:46 pm, edited 1 time in total.
mrburnette
Posts: 410
Joined: Thu Dec 19, 2019 1:23 am
Answers: 1

Re: Serial output directly into NodeRED

Post by mrburnette »

The above is not intended to be a tutorial, just some screenshots of an old project. Seems like everyone wants graphics but doing it inside the microcontroller may not be the best idea. Chances are you already have the groundwork of a serial debug stream, so I am just suggesting that you may wish to capitalize on what you already have with minimal changes to the Arduino side and move the graphics over to a real IoT solution on a NodeRED server hosted on an old PC or on a Raspberry Pi.

Lots of NodeRED instruction and training materials online. Some good videos on YouTube, too.

Have fun,

Ray
ag123
Posts: 732
Joined: Thu Dec 19, 2019 5:30 am
Answers: 3

Re: Serial output directly into NodeRED

Post by ag123 »

nice, need to find time to play with this :)
BennehBoy
Posts: 124
Joined: Sat Jan 04, 2020 2:38 am
Answers: 1

Re: Serial output directly into NodeRED

Post by BennehBoy »

Thanks for sharing more detail on this Ray.

I've had a blast this evening dusting off some old rpi's and using an ftdi to run them headless via serial console :D Without the dekstop running even my ancient rpi 1 B seems able to do more than I'd thought.
mrburnette
Posts: 410
Joined: Thu Dec 19, 2019 1:23 am
Answers: 1

Re: Serial output directly into NodeRED

Post by mrburnette »

BennehBoy wrote:
Wed Mar 10, 2021 7:44 pm
Thanks for sharing more detail on this Ray.

I've had a blast this evening dusting off some old rpi's and using an ftdi to run them headless via serial console :D Without the dekstop running even my ancient rpi 1 B seems able to do more than I'd thought.
The X-server consumes resources, that is certain. I run several Pi's headless, all of my internet radios.

On Win10, I just use TeraTerm ... so easy.
TeraTerm.JPG
TeraTerm.JPG (70.76 KiB) Viewed 1437 times
Post Reply

Return to “Ideas & suggestions”