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
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
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?
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:
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