@@ -34,13 +34,10 @@ int CWifi::begin(const char* ssid, const char *passphrase) {
34
34
35
35
unsigned long start_time = millis ();
36
36
while (millis () - start_time < 10000 ){
37
- if (modem.write (string (PROMPT (_GETSTATUS)),res,CMD (_GETSTATUS))) {
38
- if (atoi (res.c_str ()) == WL_CONNECTED) {
39
- return WL_CONNECTED;
40
- }
41
- }
37
+ if (status () == WL_CONNECTED) {
38
+ return WL_CONNECTED;
39
+ }
42
40
}
43
-
44
41
return WL_CONNECT_FAILED;
45
42
}
46
43
@@ -74,11 +71,33 @@ uint8_t CWifi::beginAP(const char *ssid, const char* passphrase, uint8_t channel
74
71
/* -------------------------------------------------------------------------- */
75
72
void CWifi::config (IPAddress local_ip) {
76
73
/* -------------------------------------------------------------------------- */
74
+ IPAddress _gw (local_ip[0 ],local_ip[1 ], local_ip[2 ], 1 );
75
+ Serial.println (_gw);
76
+ IPAddress _sm (255 ,255 ,255 ,0 );
77
+ return _config (local_ip, _gw, _sm);
77
78
}
78
79
79
80
/* -------------------------------------------------------------------------- */
80
81
void CWifi::_config (IPAddress local_ip, IPAddress gateway, IPAddress subnet) {
81
- /* -------------------------------------------------------------------------- */
82
+ /* -------------------------------------------------------------------------- */
83
+ string res = " " ;
84
+ modem.begin ();
85
+ string ip = to_string (local_ip[0 ]) + " ." ;
86
+ ip += to_string (local_ip[1 ]) + " ." ;
87
+ ip += to_string (local_ip[2 ]) + " ." ;
88
+ ip += to_string (local_ip[3 ]);
89
+
90
+ string gw = to_string (gateway[0 ]) + " ." ;
91
+ gw += to_string (gateway[1 ]) + " ." ;
92
+ gw += to_string (gateway[2 ]) + " ." ;
93
+ gw += to_string (gateway[3 ]);
94
+
95
+ string nm = to_string (subnet[0 ]) + " ." ;
96
+ nm += to_string (subnet[1 ]) + " ." ;
97
+ nm += to_string (subnet[2 ]) + " ." ;
98
+ nm += to_string (subnet[3 ]);
99
+
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 ());
82
101
}
83
102
84
103
/* -------------------------------------------------------------------------- */
@@ -114,6 +133,14 @@ void CWifi::setHostname(const char* name) {
114
133
/* -------------------------------------------------------------------------- */
115
134
int CWifi::disconnect () {
116
135
/* -------------------------------------------------------------------------- */
136
+ string res = " " ;
137
+ modem.begin ();
138
+
139
+ if (modem.write (string (PROMPT (_DISCONNECT)),res,CMD (_DISCONNECT))) {
140
+ return 1 ;
141
+ }
142
+ return 0 ;
143
+
117
144
}
118
145
119
146
/* -------------------------------------------------------------------------- */
0 commit comments