.. |br| raw:: html
.. _ex_ntrip: NTRIP ===== NTRIP client and NTRIP server related examples. NTRIP client application ------------------------ This example application connects to a NTRIP caster and forwards the RTCM corrections to GPS1. |br| It prints on the terminal some basic input/output data statistics. .. note:: Make sure to adapt the network connection to yours (fixed IP or DHCP). |br| You need to make sure your GPS1 is properly configured at 115200bps and able to send NMEA GGA and receive RTCM corrections on UART1. |br| You will need to use your own NTRIP credentials, the ones on the example will not work. :: import socket import time import machine import sbc import uasyncio as asyncio import network import sbc.ntr async def task_gps1(gps_reader, ntr_cli): nmea_parser = sbc.NMEA_parser(cb = ntr_cli.nmea_process) while True: if(ntr_cli.active): data = await gps_reader.read(32) ret = nmea_parser.parse(data) else: await asyncio.sleep(1) def ntr_cli_cb(rtcm): gps1.write(rtcm) print('NTRIP Client total data consumption: In', ntr_cli.stats_in, 'B / Out', ntr_cli.stats_out, 'B') lan = network.LAN() lan_dhcp = False while(not lan.active()): try: lan.active(True) except: print('Ethernet interface not found') time.sleep(1) if(not lan_dhcp): (lan_ip, lan_subnet, lan_gateway, lan_dns) = ("10.0.0.1", "255.255.255.0", "10.0.0.2", "8.8.8.8") lan.ifconfig((lan_ip, lan_subnet, lan_gateway, lan_dns)) print('LAN connected, configuration (ip, subnet, gateway, dns): ', lan.ifconfig()) ntr_cli = sbc.ntr.Ntr_Cli(user = 'ardusimple:1234', host = 'rtk2go.com', port = '2101', mp = 'ARDU1', periodGGA_s = 10) gps1 = sbc.Gps(1, 115200) gps1_reader = asyncio.StreamReader(gps1.get_uart_id()) loop = asyncio.get_event_loop() loop.create_task(task_gps1(gps1_reader, ntr_cli)) loop.create_task(ntr_cli.ntr_cli(lan, ntr_cli_cb)) ntr_cli.enable() loop.run_forever() NTRIP server application ------------------------ This example application connects to a NTRIP caster and sends SBC RTCM corrections to it. |br| It prints on the terminal some basic input/output data statistics. .. note:: Make sure to adapt the network connection to yours (fixed IP or DHCP). |br| You need to make sure your GPS1 is properly configured as a base station at 115200bps and able to send RTCM corrections on UART1. |br| You will need to use your own NTRIP caster credentials, the ones on the example will not work. :: import socket import time import machine import sbc import uasyncio as asyncio import network import sbc.sck import sbc.ntr async def print_stats(ntr_srv): ntr_srv_stats = 0 while True: print('NTRIP Server total data consumption: Out', ntr_srv.sck.stats_out, 'B') ntr_srv_stats = ntr_srv.sck.stats_out await asyncio.sleep(1) async def task_gps1(gps_reader, ntr_srv): while True: if(ntr_srv.active): buf = await gps_reader.read(256) ret = await ntr_srv.sendRTCM(buf) else: await asyncio.sleep(1) lan = network.LAN() lan_dhcp = False while(not lan.active()): try: lan.active(True) except: print('Ethernet interface not found') time.sleep(1) if(not lan_dhcp): (lan_ip, lan_subnet, lan_gateway, lan_dns) = ("10.0.0.1", "255.255.255.0", "10.0.0.2", "8.8.8.8") lan.ifconfig((lan_ip, lan_subnet, lan_gateway, lan_dns)) print('LAN connected, configuration (ip, subnet, gateway, dns): ', lan.ifconfig()) sck_cli = sbc.sck.Sck_Cli(host = 'rtk2go.com', port = '2101') ntr_srv = sbc.ntr.Ntr_Srv(sck = sck_cli, user = '', pwd = '1234', mp = 'ARDU1') gps1 = sbc.Gps(1, 115200) gps1_reader = asyncio.StreamReader(gps1.get_uart_id()) loop = asyncio.get_event_loop() loop.create_task(task_gps1(gps1_reader, ntr_srv)) loop.create_task(sck_cli.sck_cli(lan)) loop.create_task(ntr_srv.ntr_srv()) loop.create_task(print_stats(ntr_srv)) ntr_srv.enable() loop.run_forever()