GPS Code on Github

Hi,
I am a beginner with M2M Base Starter. I need to program an API using collecting the location information of the device. I have the Base Starter Set and a GPS module.
I copied and pasted the code of GPS from Github page, but it shows many errors, mainly with the “=” sign in the code on data descriptor section, can you please help me?
I have already tried the example from tutorial (voltage example) on your website, it works perfect!

Thank you very much!
Best regards,
Siyu

Hello @se171011

you are using the XML-Notation for the Data Descriptor, which is only to be used for directly entering the Data Descriptor via the web interface of the rapidM2M Portal. In *.dde files of the rapidM2M Studio you have to use an other much easier notation. I thing you are using the “80_GNSS_NMEA_system_0.p” example from GitHub? For this example the Data Descriptor should look like follows:

#histdata0 measurements up
Lon		s32		title=Longitude	    units=°		vscale=0.000001		decpl=6
Lat		s32		title=Latitude		units=°		vscale=0.000001		decpl=6

The examples on GitHub were created for an older developer tool which has now been replaced by the rapidM2M Studio. The source code of these examples still works in rapidM2M Studio, only the Data Descriptor needs to be adjusted.

The “GNSS_NMEA_system” example is now also available in the “M2 BASE STARTER BASIC EXAMPLES COLLECTION” Project example of the rapidM2M Studio

Kind regards
Josef

Hi Josef,
thank you very much!

I have another question, I have connected GPS according to the instruction given on the Forum:
3V3 ( red ) 3V3 <=250mA
GND ( black ) any GND
UART ( green ) UART0 RX
UART ( yellow ) UART0 TX
I2C ( orange ) I2C SCL
I2C ( white ) I2C SDA

I want to use Rapid M2M API Playground Site’s position query to get the location of the board: GET /1/customers/$CID/sites/$SID/pos/youngest
But it shows error 403 { “err”: “E_FORBIDDEN” }
Do you know why that happened? I already activated API under “My Details”.

Thank you very much for your help.
Best regards,
Siyu

Hello @se171011,

first of all:
By default, “GET /1/customers/$CID/sites/$SID/pos/youngest” returns only the position based on a calculation based on the cell towers in the receiving range of the device (GSM cell location method). The advantage of this method is, that no additional hardware is required. Therefore it is supported by all rapidM2M device types. But this method is not as accurate as using an external GNSS receiver. Without additional code (for example the code from the “GNSS_NMEA_system” example in the “M2 BASE STARTER BASIC EXAMPLES COLLECTION” Project example) your GPS is not used.

In the “GNSS_NMEA_system” example the “Longitude” and “Latitude” are saved as historic data and can be read via “GET /1/customers/$CID/sites/$SID/histdata0/youngest”. Historic data means that for example the position is recorded over a longer period of time and you can access older record.

To read the GPS position via “GET /1/customers/$CID/sites/$SID/pos/youngest” you need to transfer the position information using either the function “rM2M_SetPos()” or “rM2M_SetPosNMEA()” (see Position) to the firmware of the device. The disadvantage of this method is that you only get the last position. No historic records are available. The advantage of this method is that if you click on the “show position” symbol in the list of sites you will see the exact position of the device instead of a circle within which the device is located.

Now to your problem:

You have to select the “$CID” (Customer ID) and the “$SID” (Site ID) by using the two dropdown list above the window containing the “GET /1/customers/$CID/sites/$SID/pos/youngest” command. In the dropdown list for the Customer ID should be only one entry. In the dropdown list for the Site ID you have to select the name of the site for which you want to read the position data. If you have created several sites on the rapidM2M portal this list contains several entries.

Kind regards
Josef

Hi Josef,

thank you.
I tried the Base Starter Example collection.
I need the console record GPS location at certain time interval, just like in the example from the tutorial does (which records the voltage level at fixed interval). I guess I still need the example from GitHub?
I tried the 80_GNSS_NMEA_system_0.p, and used the main.dde lines you suggested, but the error message shows that
DLO cannot read from file “.\rapidM2M M2\mx.inc”
which comes from the line in the code: #include “.\rapidM2M M2\mx.inc”

How should I solve that problem?
Thank you for your help.

Best regards,
Siyu

Hello @se171011,

as I mentioned earlier the examples on GitHub were created for an older developer tool. If there is an version of an Github example in the “M2 BASE STARTER BASIC EXAMPLES COLLECTION” you should use this code instead of the code from Github. The examples in the “M2 BASE STARTER BASIC EXAMPLES COLLECTION” use the new libraries of the rapidM2M Studio which allow to reduce the code necessary for creating the applications. The “80_GNSS_NMEA_system\Step_0.inc” example is currently not fully optimized but uses already the “~stdlib” so the line “#include “.\rapidM2M M2\mx.inc” “ is not required. To activate this example follow the instruction of the “main.p” file of the “M2 BASE STARTER BASIC EXAMPLES COLLECTION” and remove the “/*” mark before the “#define GNSS_NMEA_system”. To view the source code for this example in the rapidM2M Studio switch to “expert mode”.

After that click first “DLO” and then “80_GNSS_NMEA_system” and “Step_0.inc”

Kind regards
Josef

Hi Josef,

thank you very much. I am really sorry to bother you with all the questions. I finally got it to work.
I changed the transmission time to 10 sec. But I see no GPS data in the Testbed and also no data in report. I also tried to be closer to the window. However, the red cable connected to the 3V3 is broken, I tried to fix it by wrapping the wires around the small metal, the blue light in the GPS is on. What could be the possible reasons for not getting GPS signal?


Thank you very much!
Siyu

Hello @se171011,

wrapping the wire around the small metal is not a good idea. You should solder the wire again. It seems to me that you have connected the UART data lines with the wrong pins (UART 1 instead of UART 0).
image

In the example the UART 0 is used.


To solve your problem you either can change the marked line to “PORT_UART =1,” to use the second UART interface (UART1) or connect the UART data lines with the pins I marked in the first picture (“UART0 RX” and “UART0 TX”).
Kind regards
Josef

Hello @se171011,

You should not set the transmission time to lower values than 10 minutes as every time the “rM2M_TxStart()” function is called in addition to transferring the measurement data a full sync of all data containers is done. This results in higher costs. If the data on the rapidM2M Portal should be updated faster than every 10 minutes it is recommended to use the “online” transmission mode.

In online mode there is an active connection between the rapidM2M Base Starter and the rapidM2M Portal. If the rapidM2M Base Starter records a data set it is immediately transmitted to the rapidM2M Portal. At the same way a modification to one of the config parameters is instantly sent from the rapidM2M Portal to the rapidM2M Base Starter. This mode requires a lot of energy.

You should set the transmission time to 60min and activate the “online” transmission mode by changing the marked line to “TXMODE = RM2M_TXMODE_ONLINE,”.

Kind regards
Josef

Hi Josef,
thank you very much for pointing out my mistakes. I tried again, now the Testbed shows:

12:49:30.457 GGA Frame erkannt: Talker-ID=0, Sentence-ID=0, Lat=0, Long=0, Alt=0, Qual=0, SatUsed=0, HDOP=0
12:49:31.003 iRecTimer=9 iTxTimer=189
12:49:31.455 GGA Frame erkannt: Talker-ID=0, Sentence-ID=0, Lat=0, Long=0, Alt=0, Qual=0, SatUsed=0, HDOP=0
12:49:32.003 iRecTimer=8 iTxTimer=188
12:49:33.030 iRecTimer=7 iTxTimer=187
12:49:33.199 GGA Frame erkannt: Talker-ID=0, Sentence-ID=0, Lat=0, Long=0, Alt=0, Qual=0, SatUsed=0, HDOP=0

Does that mean my GPS is not detected by satellites?

Best regards,

Siyu

Hello @se171011,

It seems to my your GPS receiver is not able to detect GPS signals from the satellites. A GPS antenna should be placed in such a position that there is a clear view to the sky. The determination of the position by means of GPS in buildings is usually not possible. You may be able to receive a GPS signal near a window. But this only if there is as clear a view as possible to the horizon. If there is a high building opposite the window, no GPS signal can be received here either.

Kind regards
Josef

Hi Josef,
thank you very much! I appreciate all your help!
I will try it outside again!
Best regards,
Siyu

Hi Josef,

as far as I understand from your earlier reply, if my project is using the sample code of GNSS_NMEA_system, with the line “GET /1/customers/$CID/sites/$SID/histdata0/youngest”, I will be able to get historical GPS position data in rapidM2M Playground? But how do I define the time frame, for example, from 01.01.2020 to 01.02.2020?

If I use “GET /1/customers/$CID/sites/$SID/pos/youngest”, how do I insert “rM2M_SetPosNMEA()” into the sample code GNSS_NMEA_system?

Thank you for your help!
Best regards,
Siyu

Hello @se171011,

the rapidM2M Playground enables you to familiarise yourself with the API of the rapidM2M Portal and to test the provided functions. On the left side below the input fields for username and password there is a list of the available HTTP commands. The HTTP commands are grouped according to their fields of application. You have already used “GET /1/customers/$CID/sites/$SID/histdata0/youngest” (Site´s time series data -> QUERY the youngest raw value") from that list. This command only returns the youngest data record. To get the recorded data for a specific time window you have to use the “GET /1/customers/$CID/sites/$SID/histdata0” (Site´s time series data -> QUERY the time-window with raw values") command located in the list right below the “QUERY the youngest raw value” command.

Once you have selected a command you will find a description for the command in the center of the rapidM2M Playground. A detailed description of the user interface of the rapidM2M Playground can be found here:rapidM2M Playground Overview

As you can see in the description of the “rM2M_SetPosNMEA()” function (see Position ) an NMEA data record from a GPS receiver is required as input. The “rM2M_DecodeNMEA()” function which is already used in the 80_GNSS_NMEA_system example to decode the NMEA frame also needs this type of input. Therefore the best position to integrate the “rM2M_SetPosNMEA()” function is right below the “rM2M_DecodeNMEA()” function

Kind regards
Josef

Hi Josef,

thank you for your reply.
I have another question, when I try to get the youngest GPS data, why is the data in Array format but not in Json format?


But with other query such as GET /1/customers/$CID/sites/$SID/blueprint
the data comes out as Json format. Is there anyway to make the GPS data also in Json format?
Thank you!

Hello @se171011

An array like provided in your example is perfectly fine json data, as json does not only provide objects but also arrays and primitives (numbers, strings, …) too. We use arrays to represent historical data in order to avoid sending all the repeating key values for every histdata entry. You may be assured that the order inside the array is always the same, in the case of pos/youngest:

stamp      t_stamp   original recording stamp, UTC w/o time saving.
lat        float     Latitude
long       float     Longitude
precision  int       Precision in [m]

You may find this information in the API Playground “Site’s position data”

As GPS position data is also stored historically (not only the latest value/state is available but rather all records with their corresponding timestamps) it uses the same principle as every histdata0…9 channel and is not only providing the possibility to read the latest value but also values based on a requested time window, see playground “a time-window of position values”. As in the case of multiple values available for a given time window an array only needs about ½ of the data to be transmitted.

Kind regards
Microtronics Engineering

Thank you very much for replying!
I have one more question:
I am using the code provided by IoTDev from this thread in the forum (HTTP Request to access the Microtronics REST API)
But I cannot get the data, I tried Postman App and had no problem to get the youngest array, but I hope to use JS to get the data, the console keeps on showing Error on Authentication:
const api_url = ‘https://cloud.microtronics.at/api/1/customers/myUserName/sites/[mySiteName]/pos/youngest’;
axios.get(api_url, {}, {
headers: {“Authorization”: "Basic " + base64_encode(myUserName:myPassword)}
}).then(function(response) {
console.log(‘Authenticated’);
}).catch(function(error) {
console.log(‘Error on Authentication’);
});

I double checked the base64 encode of my username and password. Can you please take a look? Thank you very much!

Hello @se171011,

are you sure you’ve included the “axios” library in your HTML code? Here you can download the library (or integrate it directly using this link):
https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js

Kind regards
Josef

Hi Josef,
thank you very much for your reply.
Yes, I did include it in my html. Here is the full code:

<html lang='en'>

    <head>

        <meta charset='UTF-8'/>

        <title>Fetch GPS Data from API</title>

    </head>

    <body>

        <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js"></script>

        <script>

            const api_url = 'https://cloud.microtronics.at/api/1/customers/se171011@emailaddress.com/sites/[mySiteName]/pos/youngest';

            axios.get(api_url, {}, {

             headers: {"Authorization":  "Basic" + "base64_encode(myUserName:myPassword)"}

            }).then(function(response) {

             console.log('Authenticated');

            }).catch(function(error) {

             console.log('Error on Authentication');

            });

        </script>

    </body>

</html>

Here is what I get in my console:

It is pretty strange, because I use Postman App, there is no problem to get the data through authentication.
Best regards

Hello @se171011,

I think the problem is that the URL Parameters are not encoded. You should use the encodeURIComponent() method. In your case, the method should be used as follows:

const api_url = "https://cloud.microtronics.at/api/1/customers/" + encodeURIComponent("se171011@emailaddress.com") + "/sites/" + encodeURIComponent("mySiteName")+ "/pos/youngest";

Kind regards
Josef