Skip to content

Commit 416b625

Browse files
committed
implemented set_ip
Former-commit-id: bbe029e
1 parent 229a9b6 commit 416b625

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

libraries/WiFiS3/src/WiFi.cpp

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ int CWifi::begin(const char* ssid, const char *passphrase) {
3434

3535
unsigned long start_time = millis();
3636
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+
}
4240
}
43-
4441
return WL_CONNECT_FAILED;
4542
}
4643

@@ -74,11 +71,33 @@ uint8_t CWifi::beginAP(const char *ssid, const char* passphrase, uint8_t channel
7471
/* -------------------------------------------------------------------------- */
7572
void CWifi::config(IPAddress local_ip) {
7673
/* -------------------------------------------------------------------------- */
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);
7778
}
7879

7980
/* -------------------------------------------------------------------------- */
8081
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());
82101
}
83102

84103
/* -------------------------------------------------------------------------- */
@@ -114,6 +133,14 @@ void CWifi::setHostname(const char* name) {
114133
/* -------------------------------------------------------------------------- */
115134
int CWifi::disconnect() {
116135
/* -------------------------------------------------------------------------- */
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+
117144
}
118145

119146
/* -------------------------------------------------------------------------- */

0 commit comments

Comments
 (0)