Example18_PointPerfectClient.ino code q if (ok) ok =

I bought this board SparkFun GPS-RTK-SMA Breakout - ZED-F9P and using this code in the arduino library folder

C:\Users.…\Documents\Arduino\libraries\SparkFun_u-blox_GNSS_Arduino_Library\examples\ZED-F9P\Example18_PointPerfectClient there is a file called Example18_PointPerfectClient.ino

the code is running fine but I am trying to understand what this code does: It appears to perhaps get a return value from calling functions but cannot understand what it does. Usually an if statement has a else part to it. Is it some kind of error trapping ? thanks

#define OK(ok) (ok ? F(" → OK") : F(" → ERROR!")) // Convert uint8_t into OK/ERROR

uint8_t ok = myGNSS.setI2COutput(COM_TYPE_UBX); //Turn off NMEA noise

if (ok) ok = myGNSS.setI2CInput(COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_SPARTN); // Be sure SPARTN input is enabled.

if (ok) ok = myGNSS.setDGNSSConfiguration(SFE_UBLOX_DGNSS_MODE_FIXED); // Set the differential mode - ambiguities are fixed whenever possible

if (ok) ok = myGNSS.setNavigationFrequency(1); //Set output in Hz.

if (ok) ok = myGNSS.setVal8(UBLOX_CFG_SPARTN_USE_SOURCE, 0); // Use IP source (default). Change this to 1 for L-Band (PMP)

Hi,

It’s mostly just code shorthand. Sorry about that!

Those functions / methods return a bool (boolean) to say if they were successful or not. ok is uint8_t (unsigned 8-bit integer) but is actually just holding a bool (true = 1, false = 0). “if (ok)” is the same as writing “if (ok == true)”. Each line is written in the style “if the last line was ok, then do this line”. Including {} brackets for clarity, each line becomes:

if (ok == true)

{

ok = myGNSS.setI2CInput(COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_SPARTN); // Be sure SPARTN input is enabled.

}

If any one function / method fails then ok becomes false and the rest are skipped.

OK(ok) is more shorthand. It’s actually a macro that returns the text " → OK" or " → ERROR!" depending on whether ok is true or false. The question mark ? is shorthand for “if (ok == true)”. If ok is true, the code does the first thing (returns " → OK" as Flash Helper text. The F tells the compiler to keep the text in program memory, instead of storing it in RAM). If ok is NOT true, the code does the second thing - after the colon : - and returns" → ERROR!" instead.

Another nice piece of shorthand is as follows:

bool ok = true; // Set ok to true initially

// logical AND (&=) each result into ok. All lines are executed. If any one line fails, ok will be false

ok &= myGNSS.setI2CInput(COM_TYPE_UBX | COM_TYPE_NMEA | COM_TYPE_SPARTN);

ok &= myGNSS.setNavigationFrequency(1);

ok &= myGNSS.setVal8(UBLOX_CFG_SPARTN_USE_SOURCE, 0);

Serial.println(OK(ok)); // Will print → OK if all lines returned true, → ERROR if any one line failed

Enjoy!

Paul

thanks Paul

Hi,. my name is Bernhard and I use the code example 18 together with a Saparkfun RTK SMA board.

I don´t get connection to the MQTT/SPARTN client and the error code -2 appears. I believe that I put the certificates in the wrong way. Can somebody show me how to put the credentials into the code of example 18?

Thanks a lot.

Bernhard

Hi

regarding the post earlier;this is what I get from the Arduino Monitor:

12:21:36.178 → sssssssssessssssssssss HSPs±eLsess0,wp_drv:0x00

12:22:35.888 → mode: DIO, clock div:1

12:22:35.888-› load:0x3fff0030,len:1344

12:22:35.888->load:0x40078000,len:13864

12:22:35.888-›load:0x40080400,len:3608

12:22:35.888 → entry 0x400805f0

12:22:37.215-› PointPerfect testing

12:22:37.316-> U-blox GNSS module connected

12:22:37.960-> GNSS: configuration -ERROR!

12 • 22 • 37 960-› Connecting to local WiFi

12:22:38.560 - WiFi connected with IP: 192.168.178.121

12:22:38.560 → Press any key to start MQTT/SPARTN Client.

12:23:20.952 → Subscribing to Broker. Press key to stop

12:23:21.062 → MOTT connection failed! Error code-2

12:23:21.062 → Press any key to start MQTT/SPARTN Client.

regards Bernhard

Hello Bernhard,

It should look like the attached. You copy the Client ID, Certificates and Key directly from the PointPerfect Location Thing credentials.

I hope this helps,

Paul

Hi Paul,

thanks for your fast replay.

I could put in the Root Certification,. as you described, but the Client Certification and the Client Key came through the download in a certificate.

Bildschirmfoto 2023-03-12 um 20.17.23.png

I hope you can give me a hint.

Hello George,

After you have downloaded the files, open them with a text editor. Then you can copy and paste the certificate / key.

On Windows, right-click on the file name in Explorer, choose “Open With” and select a text editor. Notepad works well. You might have to select “Choose Another App” and then select Notepad from the list:

Best wishes,

Paul

Example18_4.jpg

Hi Paul,

I use a Mac book. Do you know how it works with that?

Bernhard

Hi Paul,

I got it!! Thanks a lot :slight_smile: :slight_smile:

Bernhard

Hello Paul,

I put everthing right in, but I get still an error message:

12:21:36.178 → sssssssssessssssssssss HSPs±eLsess0,wp_drv:0x00

12:22:35.888 → mode: DIO, clock div:1

12:22:35.888-› load:0x3fff0030,len:1344

12:22:35.888->load:0x40078000,len:13864

12:22:35.888-›load:0x40080400,len:3608

12:22:35.888 → entry 0x400805f0

12:22:37.215-› PointPerfect testing

12:22:37.316-> U-blox GNSS module connected

12:22:37.960-> GNSS: configuration -ERROR!

12 • 22 • 37 960-› Connecting to local WiFi

12:22:38.560 - WiFi connected with IP: 192.168.178.121

12:22:38.560 → Press any key to start MQTT/SPARTN Client.

12:23:20.952 → Subscribing to Broker. Press key to stop

12:23:21.062 → MOTT connection failed! Error code-2

12:23:21.062 → Press any key to start MQTT/SPARTN Client.

regards Bernhard

Hello Bernhard,

Please check that you copied and pasted all four credentials correctly:

// → Credentials → Client Id

static const char MQTT_CLIENT_ID = “”;

// → Credentials → Amazon Root Certificate

static const char AWS_CERT_CA PROGMEM = R"EOF(

-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----

)EOF";

// → Credentials → Client Certificate

static const char AWS_CERT_CRT PROGMEM = R"KEY(

-----BEGIN CERTIFICATE-----

-----END CERTIFICATE-----

)KEY";

// Get this from Thingstream Portal

// → Credentials → Client Key

static const char AWS_CERT_PRIVATE PROGMEM = R"KEY(

-----BEGIN RSA PRIVATE KEY-----

-----END RSA PRIVATE KEY-----

)KEY";

Also, you should not see the message “GNSS: configuration -ERROR!”. This means something has gone wrong when configuring the ZED module. This is not causing the MQTT error, but it will stop the example from working correctly. I think you need to update your ZED-F9P. I do not know if this is possible on Mac. I only have Windows solutions (u-center and our update tool). Please see: https://learn.sparkfun.com/tutorials/ho … s-receiver and https://github.com/sparkfun/SparkFun_RT … Update_GUI

Best wishes,

Paul