@@ -74,11 +74,12 @@ void CWifi::config(IPAddress local_ip) {
74
74
IPAddress _gw (local_ip[0 ],local_ip[1 ], local_ip[2 ], 1 );
75
75
Serial.println (_gw);
76
76
IPAddress _sm (255 ,255 ,255 ,0 );
77
- return _config (local_ip, _gw, _sm);
77
+ IPAddress dns (0 ,0 ,0 ,0 );
78
+ return _config (local_ip, _gw, _sm,dns,dns);
78
79
}
79
80
80
81
/* -------------------------------------------------------------------------- */
81
- void CWifi::_config (IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
82
+ void CWifi::_config (IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2 ) {
82
83
/* -------------------------------------------------------------------------- */
83
84
string res = " " ;
84
85
modem.begin ();
@@ -97,32 +98,55 @@ void CWifi::_config(IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
97
98
nm += to_string (subnet[2 ]) + " ." ;
98
99
nm += to_string (subnet[3 ]);
99
100
100
- modem.write (string (PROMPT (_SETIP)),res, " %s%s,%s,%s\r\n " , CMD_WRITE (_SETIP), ip.c_str (), gw.c_str (), nm.c_str ());
101
+ string _dns1 = to_string (dns1[0 ]) + " ." ;
102
+ _dns1 += to_string (dns1[1 ]) + " ." ;
103
+ _dns1 += to_string (dns1[2 ]) + " ." ;
104
+ _dns1 += to_string (dns1[3 ]);
105
+
106
+ string _dns2 = to_string (dns2[0 ]) + " ." ;
107
+ _dns2 += to_string (dns2[1 ]) + " ." ;
108
+ _dns2 += to_string (dns2[2 ]) + " ." ;
109
+ _dns2 += to_string (dns2[3 ]);
110
+
111
+ modem.write (string (PROMPT (_SETIP)),res, " %s%s,%s,%s,%s,%s\r\n " , CMD_WRITE (_SETIP), ip.c_str (), gw.c_str (), nm.c_str (),_dns1.c_str (),_dns2.c_str ());
101
112
}
102
113
103
114
/* -------------------------------------------------------------------------- */
104
115
void CWifi::config (IPAddress local_ip, IPAddress dns_server) {
105
- /* -------------------------------------------------------------------------- */
116
+ /* -------------------------------------------------------------------------- */
117
+ IPAddress _gw (local_ip[0 ],local_ip[1 ], local_ip[2 ], 1 );
118
+ Serial.println (_gw);
119
+ IPAddress _sm (255 ,255 ,255 ,0 );
120
+ IPAddress dns (0 ,0 ,0 ,0 );
121
+ return _config (local_ip, _gw, _sm,dns_server,dns);
106
122
}
107
123
108
124
/* -------------------------------------------------------------------------- */
109
125
void CWifi::config (IPAddress local_ip, IPAddress dns_server, IPAddress gateway) {
110
- /* -------------------------------------------------------------------------- */
126
+ /* -------------------------------------------------------------------------- */
127
+ IPAddress _sm (255 ,255 ,255 ,0 );
128
+ IPAddress dns (0 ,0 ,0 ,0 );
129
+ return _config (local_ip, gateway, _sm,dns_server,dns);
111
130
}
112
131
113
132
/* -------------------------------------------------------------------------- */
114
133
void CWifi::config (IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet) {
115
134
/* -------------------------------------------------------------------------- */
135
+ IPAddress dns (0 ,0 ,0 ,0 );
136
+ return _config (local_ip, gateway, subnet,dns_server,dns);
116
137
}
117
138
118
139
/* -------------------------------------------------------------------------- */
119
140
void CWifi::setDNS (IPAddress dns_server1) {
120
- /* -------------------------------------------------------------------------- */
141
+ /* -------------------------------------------------------------------------- */
142
+ IPAddress dns (0 ,0 ,0 ,0 );
143
+ return _config (localIP (), gatewayIP (), subnetMask (),dns_server1,dns);
121
144
}
122
145
123
146
/* -------------------------------------------------------------------------- */
124
147
void CWifi::setDNS (IPAddress dns_server1, IPAddress dns_server2) {
125
148
/* -------------------------------------------------------------------------- */
149
+ return _config (localIP (), gatewayIP (), subnetMask (),dns_server1,dns_server2);
126
150
}
127
151
128
152
/* -------------------------------------------------------------------------- */
@@ -203,9 +227,33 @@ int8_t CWifi::scanNetworks() {
203
227
return (int8_t )access_points.size ();
204
228
}
205
229
230
+ /* -------------------------------------------------------------------------- */
231
+ IPAddress CWifi::dnsIP (int n) {
232
+ /* -------------------------------------------------------------------------- */
233
+ modem.begin ();
234
+ string res;
235
+ if (n == 0 ) {
236
+ if (modem.write (string (PROMPT (_IPSTA)),res, " %s%d\r\n " , CMD_WRITE (_IPSTA), DNS1_ADDR)) {
237
+ IPAddress dns_IP;
238
+ dns_IP.fromString (res.c_str ());
239
+ return dns_IP;
240
+ }
241
+ }
242
+ else if (n == 1 ) {
243
+ if (modem.write (string (PROMPT (_IPSTA)),res, " %s%d\r\n " , CMD_WRITE (_IPSTA), DNS2_ADDR)) {
244
+ IPAddress dns_IP;
245
+ dns_IP.fromString (res.c_str ());
246
+ return dns_IP;
247
+ }
248
+ }
249
+ return IPAddress (0 ,0 ,0 ,0 );
250
+ }
251
+
252
+
206
253
/* -------------------------------------------------------------------------- */
207
254
IPAddress CWifi::localIP () {
208
255
/* -------------------------------------------------------------------------- */
256
+ modem.begin ();
209
257
string res = " " ;
210
258
if (modem.write (string (PROMPT (_IPSTA)),res, " %s%d\r\n " , CMD_WRITE (_IPSTA), IP_ADDR)) {
211
259
IPAddress local_IP;
@@ -218,6 +266,7 @@ IPAddress CWifi::localIP() {
218
266
/* -------------------------------------------------------------------------- */
219
267
IPAddress CWifi::subnetMask () {
220
268
/* -------------------------------------------------------------------------- */
269
+ modem.begin ();
221
270
string res = " " ;
222
271
if (modem.write (string (PROMPT (_IPSTA)),res, " %s%d\r\n " , CMD_WRITE (_IPSTA), NETMASK_ADDR)) {
223
272
IPAddress subnetMask;
@@ -230,6 +279,7 @@ IPAddress CWifi::subnetMask() {
230
279
/* -------------------------------------------------------------------------- */
231
280
IPAddress CWifi::gatewayIP () {
232
281
/* -------------------------------------------------------------------------- */
282
+ modem.begin ();
233
283
string res = " " ;
234
284
if (modem.write (string (PROMPT (_IPSTA)),res, " %s%d\r\n " , CMD_WRITE (_IPSTA), GATEWAY_ADDR)) {
235
285
IPAddress gateway_IP;
0 commit comments