forked from buched/F9p-ntrip-esp32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathF9p-ntrip-esp32-main.ino
123 lines (107 loc) · 3.21 KB
/
F9p-ntrip-esp32-main.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <WiFi.h>
#include "NTRIPClient.h"
#include <HardwareSerial.h>
HardwareSerial MySerial(2);
HardwareSerial Serialrx(1);
const char* ssid = "your_ssid";
const char* password = "your_password";
IPAddress server(192, 168, 1, 100); // IP address of the server
int port = 80;
char* host = "ntrip caster host";
int httpPort = 2101; //port 2101 is default port of NTRIP caster
char* mntpnt = "ntrip caster's mountpoint";
char* user = "ntrip caster's client user";
char* passwd = "ntrip caster's client password";
NTRIPClient ntrip_c;
const char* udpAddress = "192.168.1.255";
const int udpPort = 9999;
int trans = 0; //0 = serial, 1 = udp, 2 = tcp client, 3 = serialrx, 4 = myserial Choose wich out you want use. for rs232 set 0 et connect tx f9p directly to rs232 module
WiFiUDP udp;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(500);
MySerial.begin(115200, SERIAL_8N1, 16, 17);//serial port to send rtcm to f9p
delay(100);
Serialrx.begin(115200, SERIAL_8N1, 23, 22);
delay(100);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Requesting SourceTable.");
if(ntrip_c.reqSrcTbl(host,httpPort)){
char buffer[512];
delay(5);
while(ntrip_c.available()){
ntrip_c.readLine(buffer,sizeof(buffer));
Serial.print(buffer);
}
}
else{
Serial.println("SourceTable request error");
}
Serial.print("Requesting SourceTable is OK\n");
ntrip_c.stop(); //Need to call "stop" function for next request.
Serial.println("Requesting MountPoint's Raw data");
if(!ntrip_c.reqRaw(host,httpPort,mntpnt,user,passwd)){
delay(15000);
ESP.restart();
}
Serial.println("Requesting MountPoint is OK");
}
void loop() {
WiFiClient client;
while(ntrip_c.available())
{
char ch = ntrip_c.read();
MySerial.print(ch);
}
while (Serialrx.available())
{
String s = Serialrx.readStringUntil('\n');
switch (trans)
{
case 0: //serial out
Serial.println(s);
break;
case 1: //udp out
udp.beginPacket(udpAddress, udpPort);
udp.print(s);
udp.endPacket();
break;
case 2: //tcp client out
if (!client.connect(server, port))
{
Serial.println("connection failed");
return;
}
client.println(s);
while (client.connected())
{
while (client.available())
{
char c = client.read();
Serial.print(c);
}
}
client.stop();
break;
case 3: //serialrx out
Serialrx.println(s);
break;
case 4: //MySerial out
MySerial.println(s);
break;
default: //mauvaise config
Serial.println("mauvais choix ou oubli de configuration");
break;
}
}
}