This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| app-notes:send-the-local-gps-nmea-stream-to-a-remote-udp-server [2025/11/05 13:47] – [1. Set up the SDK script on the router] gray | app-notes:send-the-local-gps-nmea-stream-to-a-remote-udp-server [2025/11/05 14:32] (current) – [2. Additional information] gray | ||
|---|---|---|---|
| Line 62: | Line 62: | ||
| ############################################################################### | ############################################################################### | ||
| - | DEBUG=flase; # Enable debugging with true or disable with false | + | DEBUG=false; # Enable debugging with true or disable with false |
| - | DEBUGALL=flase; # Enable debugging with true or disable with false | + | DEBUGALL=false; # Enable debugging with true or disable with false |
| ############################################################################### | ############################################################################### | ||
| Line 262: | Line 262: | ||
| In the last step, we activate the SDK script on the router. | In the last step, we activate the SDK script on the router. | ||
| + | {{: | ||
| + | |||
| + | Again, enter the '' | ||
| + | |||
| + | ---- | ||
| + | {{: | ||
| + | |||
| + | Using the Administration option under '' | ||
| + | |||
| + | ---- | ||
| + | |||
| + | |||
| + | ===== - Additional information ===== | ||
| + | |||
| + | ++++show code| | ||
| + | <code – GPS_TRACKING.are> | ||
| + | /* DESC: This script sends the local GPS NMEA stream to a remote UDP server | ||
| + | * (including device identity). | ||
| + | * In addition, a Telit module is used to provide the GPRMC frame from the | ||
| + | * GNSS data block using a regular expression. | ||
| + | * Copyright (C) 2013-2025 NetModule AG, Switzerland | ||
| + | */ | ||
| + | |||
| + | ############################################################################### | ||
| + | DEBUG=false; | ||
| + | DEBUGALL=false; | ||
| + | ############################################################################### | ||
| + | |||
| + | release_point = 0; | ||
| + | |||
| + | void usage() | ||
| + | { | ||
| + | nb_syslog(" | ||
| + | printf(" | ||
| + | exit(1); | ||
| + | } | ||
| + | |||
| + | if (argc < 2) { | ||
| + | usage(); | ||
| + | } | ||
| + | |||
| + | SERVER = trim((string) argv[1]); | ||
| + | PORT = (int) argv[2]; | ||
| + | |||
| + | int gpsd_request (int fd) | ||
| + | { | ||
| + | nb_syslog(" | ||
| + | |||
| + | if (send(fd, " | ||
| + | nb_syslog(" | ||
| + | return -1; | ||
| + | } | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | |||
| + | int gpsd_init () | ||
| + | { | ||
| + | /* connect to gpsd */ | ||
| + | fd = socket(AF_INET, | ||
| + | if (fd < 0) { | ||
| + | nb_syslog(" | ||
| + | return -1; | ||
| + | } | ||
| + | |||
| + | if (connect(fd, | ||
| + | nb_syslog(" | ||
| + | close(fd); | ||
| + | return -1; | ||
| + | } | ||
| + | |||
| + | if (gpsd_request(fd) != 0) { | ||
| + | close(fd); | ||
| + | return -1; | ||
| + | } | ||
| + | |||
| + | return fd; | ||
| + | } | ||
| + | |||
| + | void gpsd_uninit (int fd) | ||
| + | { | ||
| + | if (fd >= 0) { | ||
| + | close(fd); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | int server_init () | ||
| + | { | ||
| + | /* open UDP server socket */ | ||
| + | fd = socket(AF_INET, | ||
| + | if (fd < 0) { | ||
| + | nb_syslog(" | ||
| + | return -1; | ||
| + | } else { | ||
| + | return fd; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void server_uninit (int fd) | ||
| + | { | ||
| + | if (fd >= 0) { | ||
| + | close(fd); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | int gpsd_process (int gpsd, int server) | ||
| + | { | ||
| + | /* process NMEA stream */ | ||
| + | nb_syslog(" | ||
| + | while(1) { | ||
| + | /* wait for client socket data */ | ||
| + | rv = select(gpsd, | ||
| + | if (rv == -1) { | ||
| + | nb_syslog(" | ||
| + | return -1; | ||
| + | } else if (rv == 0) { | ||
| + | /* nb_syslog(" | ||
| + | continue; | ||
| + | } | ||
| + | data = recv(gpsd); | ||
| + | if(DEBUG || DEBUGALL)printf(" | ||
| + | status = nb_status(" | ||
| + | info = struct_get(status, | ||
| + | info = right(info, | ||
| + | len = strlen(info); | ||
| + | temp = len - 6; | ||
| + | info = left(info, | ||
| + | if(DEBUGALL)printf(" | ||
| + | if (info == "Telit "){ | ||
| + | if(DEBUGALL)printf(" | ||
| + | len = strlen(data); | ||
| + | if (len > 200){ | ||
| + | if(DEBUG || DEBUGALL)printf(" | ||
| + | data_gprmc = pcre_compile(" | ||
| + | m = pcre_exec( data_gprmc, data, 0); | ||
| + | len = strlen(m[0]); | ||
| + | if(DEBUGALL)printf(" | ||
| + | if (len != 0){ | ||
| + | | ||
| + | release_point = 1; | ||
| + | } else { | ||
| + | if(DEBUGALL)printf(" | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | if (strlen(data) == 0) { | ||
| + | nb_syslog(" | ||
| + | return -1; | ||
| + | } | ||
| + | |||
| + | status = nb_status(" | ||
| + | serial = struct_get(status, | ||
| + | sentence = strcat(" | ||
| + | sentenceLength = strlen(sentence); | ||
| + | sentenceArray = explode(sentence); | ||
| + | |||
| + | checksum = 0; | ||
| + | for (i = 0; i < sentenceLength; | ||
| + | currentChar = ord(sentenceArray[i]); | ||
| + | checksum ^= currentChar; | ||
| + | } | ||
| + | |||
| + | checksum = sprintf(" | ||
| + | nmsentence = strcat(" | ||
| + | if (release_point == 0){ | ||
| + | data = strcat(data, | ||
| + | if(DEBUG || DEBUGALL)printf(" | ||
| + | } | ||
| + | if (release_point == 1){ | ||
| + | if(DEBUG || DEBUGALL)printf(" | ||
| + | m = strcat(m[0], | ||
| + | if(DEBUG || DEBUGALL)printf(" | ||
| + | release_point = 0; | ||
| + | data = m; | ||
| + | } | ||
| + | len = strlen(data); | ||
| + | if (len <= 0) continue; | ||
| + | sent = sendto(server, | ||
| + | if(DEBUG || DEBUGALL)printf(" | ||
| + | if (sent != len) { | ||
| + | nb_syslog(" | ||
| + | return -1; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | |||
| + | /* main */ | ||
| + | |||
| + | while (1) { | ||
| + | nb_syslog(" | ||
| + | gpsd = gpsd_init(); | ||
| + | server = server_init(); | ||
| + | |||
| + | if (gpsd >= 0 && server >= 0) { | ||
| + | gpsd_process(gpsd, | ||
| + | } | ||
| + | |||
| + | server_uninit(server); | ||
| + | gpsd_uninit(gpsd); | ||
| + | sleep(5); | ||
| + | } | ||
| + | exit(0); | ||
| + | </ | ||
| + | ++++ | ||
| + | |||
| + | ---- | ||