Strage issue with data over MessagePort to Arduino

Support for Arduino in combination with Air Manager and Air Player

Moderators: Ralph, russ

Post Reply
Message
Author
jaccodewijs
Posts: 3
Joined: Fri Jun 10, 2022 3:44 pm

Strage issue with data over MessagePort to Arduino

#1 Post by jaccodewijs »

Hi all,

Having the strangest issue here.

Setup:
I have an Arduino UNO connected to my Air Manager laptop (Linux Mint 19) over USB.
I am connected to FS2020 over the network, using the stock Cessna172 for testing.

The thing I wanted to do is: read the NAV1 Standby Frequency and display that on an OLED display on the Arduino UNO.
AirManager connects to my Sim alright.
I can get the right data from the sim and get it to show in the AM console.
The Arduino receives the data correctly -most of the time-, and here is where the problem is.
It seems to skip certain values consistently and I can't figure out why....

I am using SoftwareSerial on the Arduino for now for debugging, as I obviously cannot use the built-in Serial that is used by AM.

Code: Select all

Arduino UNO code:
----------------------------------------------------

#include <si_message_port.hpp>
SiMessagePort* messagePort;

#include <SoftwareSerial.h>
SoftwareSerial mySerial(7, 6); // Using SoftwareSerial for debugging


void setup() {
  messagePort = new SiMessagePort(SI_MESSAGE_PORT_DEVICE_ARDUINO_UNO, SI_MESSAGE_PORT_CHANNEL_A, new_message_callback);
  mySerial.begin(115200); 
}

void loop() {
  messagePort->Tick();
}


static void new_message_callback(uint16_t message_id, struct SiMessagePortPayload* payload) {
  if (message_id == 1){
    int x = payload->data_int[0];
    mySerial.println(x);
  }  
}





Air Manager code:
----------------------------------------------------

my_message_port = hw_message_port_add("ARDUINO_UNO_A", new_message)  
  
 function NAV1_callback(freq)
     freq=freq*100  -- do this to make data an integer (no decimals)   
     hw_message_port_send(my_message_port, 1, "INT", freq)
     print(freq) 	-- Print to Console for debugging
 end

fs2020_variable_subscribe("NAV STANDBY FREQUENCY:1", "Mhz", NAV1_callback) 


Now, when changing the NAV1 Standby Frequency in the aircraft, I get the following results:


Output from AM Console:
-----------------------
11400,0
11405,0
11410,0
11415,0
11420,0
11425,0
11430,0
11435,0
11440,0
11445,0
11450,0
11455,0
11460,0
11465,0
11470,0
11475,0
11480,0
11485,0
11490,0
11495,0
11400,0


Output from Arduino SoftwareSerial:
-----------------------------------
11400                                                                           
11405                                                                           
11410                                                                           
11415                                                                           
0                                                                               
11425                                                                           
11430                                                                           
11435                                                                           
11440                                                                           
0                                                                               
11450                                                                           
11455                                                                           
11460                                                                           
11465                                                                           
0                                                                               
11475                                                                           
11480                                                                           
11485                                                                           
11490                                                                           
0                                                                               
11400                                                                           
11405  

What's with the zero' s??

Can anyone please help me out here?
Thanks all in advance, I must be overlooking something...

Greetings,
Jacco
Last edited by jaccodewijs on Sat Jun 11, 2022 10:17 am, edited 1 time in total.

User avatar
jph
Posts: 2094
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Strage issue with data over MessagePort to Arduino

#2 Post by jph »

Jacco, Hi,
You are calling 'tick' around 1 million times a second .... :shock: :)
Firstly put a temporary delay(50); in main() and test again. Obviously you normally wouldn't use a 'full stop' delay in your final code but it is fine for testing
Air Manager is going to be trying to respond to the tick call continuously.

edit - (removed incorrect section regarding data types).
afaik Arduino is expecting Int32_t. Lua - as you mentioned after - doesn't have this as all types are effectively 'number' so there should be no issue providing you don't pass decimal places.

Also, when posting code you should always highlight the code and then press the </> button above the text writing area. This will put it / them in a scrollable window.
Thanks.
Joe
Last edited by jph on Sat Jun 11, 2022 12:41 pm, edited 1 time in total.
“Everything in moderation, including moderation.”
“Experience is merely the name men gave to their mistakes.”
Joe (CISSP) -IT security consultant

jaccodewijs
Posts: 3
Joined: Fri Jun 10, 2022 3:44 pm

Re: Strage issue with data over MessagePort to Arduino

#3 Post by jaccodewijs »

Hi Joe,

Sorry about the code formatting.
Corrected that.

I will try the 50ms delay in the Arduino loop, see if it helps.

Even though I declared the receiving datatype in the Arduino code as a long (32bits), there doesn't seem to be an equivalent for that in Air Manager, is there?
Only options there are INT, FLOAT, STRING or array variants of that.

Also, if I add 0.01 to the value of freq before sending it over MessagePort:

freq=freq*100+0.01

Then the Arduino reports -only- zero's!
How weird is that...

Will post my results once I got the chance to test with the delay in place.

Thanks!

User avatar
jph
Posts: 2094
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Strage issue with data over MessagePort to Arduino

#4 Post by jph »

The 'BYTE' 'INT' 'FLOAT' 'STRING' etc is specific to the MessagePort function afaik and allowances are made for the Arduino - for example the Arduino's Int32_t (long) expectation when using 'INT' in the AM messageport function

I believe that Lua doesn't have specific types ( so it should be handled automatically within AM. )

On further consideration, as to what happens when the float (with decimal places non zero) is sent to the messageport function when type 'INT' is set in the AM call then perhaps if decimal places are found the number is rejected in the MessagePort Function and the value that was passed is set to zero ?
Perhaps @Corjan could comment ?
Joe
“Everything in moderation, including moderation.”
“Experience is merely the name men gave to their mistakes.”
Joe (CISSP) -IT security consultant

jaccodewijs
Posts: 3
Joined: Fri Jun 10, 2022 3:44 pm

Re: Strage issue with data over MessagePort to Arduino

#5 Post by jaccodewijs »

So, I finally got it working,
Not with delays, not with using a different datatype, but I ended up subscribing to the frequency dataref as "Khz" instead of "Mhz".
That way, I could drop the conversion (*1000) in AM, send it over as an AM "INT", received it in Arduino as a long, and used the value on my display by casting it into a float...
Not pretty, but at least it is working.

Maybe there is something strange going on with the SimConnect dataref for "Mhz" in conjunction with multiplying it in AM before sending.

Hopefully someone else can benefit from this issue, that has now been resolved as far as I am concerned.

Thanks for the responses!

User avatar
jph
Posts: 2094
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Strage issue with data over MessagePort to Arduino

#6 Post by jph »

The joys (not) of the fs2020 game... :?
“Everything in moderation, including moderation.”
“Experience is merely the name men gave to their mistakes.”
Joe (CISSP) -IT security consultant

Post Reply