Skip to content

Commit 8c0115e

Browse files
committed
Implemented server
Former-commit-id: e47d524
1 parent 6186c6d commit 8c0115e

File tree

6 files changed

+45
-20
lines changed

6 files changed

+45
-20
lines changed

libraries/WiFiS3/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
by Tom Igoe
2222
*/
2323

24-
#include <WiFi.h>
25-
#include <WiFiServer.h>
24+
#include "WiFiS3.h"
2625

2726
#include "arduino_secrets.h"
2827
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
@@ -35,7 +34,7 @@ int status = WL_IDLE_STATUS;
3534
WiFiServer server(80);
3635

3736
void setup() {
38-
Serial.begin(9600); // initialize serial communication
37+
Serial.begin(115200); // initialize serial communication
3938
pinMode(led, OUTPUT); // set the LED pin mode
4039

4140
// check for the WiFi module:
@@ -46,7 +45,7 @@ void setup() {
4645
}
4746

4847
String fv = WiFi.firmwareVersion();
49-
if (fv < WiFi_FIRMWARE_LATEST_VERSION) {
48+
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
5049
Serial.println("Please upgrade the firmware");
5150
}
5251

@@ -66,6 +65,7 @@ void setup() {
6665

6766

6867
void loop() {
68+
delay(2000);
6969
WiFiClient client = server.available(); // listen for incoming clients
7070

7171
if (client) { // if you get a client,
@@ -87,8 +87,8 @@ void loop() {
8787
client.println();
8888

8989
// the content of the HTTP response follows the header:
90-
client.print("<p style=\"font-size:7vw;\">Click <a href=\"/H\">here</a> turn the LED off<br></p>");
91-
client.print("<p style=\"font-size:7vw;\">Click <a href=\"/L\">here</a> turn the LED on<br></p>");
90+
client.print("<p style=\"font-size:7vw;\">Click <a href=\"/H\">here</a> turn the LED on<br></p>");
91+
client.print("<p style=\"font-size:7vw;\">Click <a href=\"/L\">here</a> turn the LED off<br></p>");
9292

9393
// The HTTP response ends with another blank line:
9494
client.println();
@@ -109,6 +109,7 @@ void loop() {
109109
digitalWrite(LED_BUILTIN, LOW); // GET /L turns the LED off
110110
}
111111
}
112+
112113
}
113114
// close the connection:
114115
client.stop();

libraries/WiFiS3/src/Modem.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,20 @@ bool ModemClass::passthrough(const uint8_t *data, size_t size) {
4848
bool res = false;
4949
bool found = false;
5050
string data_res = "";
51+
5152
unsigned long start_time = millis();
5253
while(millis() - start_time < _timeout && !found){
5354
while(_serial->available()){
5455
char c = _serial->read();
5556
data_res += c;
57+
5658
if(string::npos != data_res.rfind(RESULT_OK)){
5759
found = true;
5860
res = true;
5961
break;
6062
}
6163
else if (string::npos != data_res.rfind(RESULT_ERROR)) {
64+
found = true;
6265
res = false;
6366
break;
6467
}
@@ -190,8 +193,19 @@ bool ModemClass::buf_read(const string &prompt, string &data_res) {
190193
found = true;
191194
read_by_size = false;
192195
res = true;
193-
while(_serial->available()){
194-
_serial->read();
196+
197+
unsigned long start = millis();
198+
bool ok_found = false;
199+
while(millis() - start < _timeout && !ok_found) {
200+
string ok = "";
201+
while(_serial->available()){
202+
char c = _serial->read();
203+
ok += c;
204+
if(ok.size() - ok.rfind("OK\r\n") == 4) {
205+
ok_found = true;
206+
break;
207+
}
208+
}
195209
}
196210
}
197211
}

libraries/WiFiS3/src/WiFiClient.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
/* -------------------------------------------------------------------------- */
44
WiFiClient::WiFiClient() : _sock(-1) { }
55
/* -------------------------------------------------------------------------- */
6+
7+
/* -------------------------------------------------------------------------- */
8+
WiFiClient::WiFiClient(int s) : _sock(s) {
9+
}
10+
/* -------------------------------------------------------------------------- */
611

712
/* -------------------------------------------------------------------------- */
813
void WiFiClient::getSocket() {
@@ -186,6 +191,9 @@ void WiFiClient::stop() {
186191
uint8_t WiFiClient::connected() {
187192
/* -------------------------------------------------------------------------- */
188193
uint8_t rv = 0;
194+
if(this->available() > 0) {
195+
return 1;
196+
}
189197
if(_sock >= 0) {
190198
string res = "";
191199
modem.begin();

libraries/WiFiS3/src/WiFiClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class WiFiClient : public Client {
3535

3636
public:
3737
WiFiClient();
38+
WiFiClient(int s);
3839
virtual int connect(IPAddress ip, uint16_t port);
3940
virtual int connect(const char *host, uint16_t port);
4041
virtual size_t write(uint8_t);
@@ -58,7 +59,7 @@ class WiFiClient : public Client {
5859
using Print::write;
5960

6061
protected:
61-
int8_t _sock;
62+
int _sock;
6263
void getSocket();
6364
FifoBuffer<uint8_t,RX_BUFFER_DIM> rx_buffer;
6465
int _read();

libraries/WiFiS3/src/WiFiS3.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222

2323
#include "WiFi.h"
2424
#include "WiFiClient.h"
25+
#include "WiFiServer.h"
2526

2627
#endif

libraries/WiFiS3/src/WiFiServer.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@
2121
#ifndef wifiserver_h
2222
#define wifiserver_h
2323

24-
extern "C" {
25-
#include "utility/wl_definitions.h"
26-
}
27-
2824
#include "Server.h"
25+
#include "Modem.h"
26+
#include "WiFiClient.h"
2927

3028
class WiFiClient;
3129

3230
class WiFiServer : public Server {
3331
private:
34-
uint8_t _sock;
35-
uint8_t _lastSock;
36-
uint16_t _port;
37-
void* pcb;
32+
int _sock;
33+
int _port;
34+
3835
public:
39-
WiFiServer(uint16_t);
40-
WiFiClient available(uint8_t* status = NULL);
36+
WiFiServer();
37+
WiFiServer(int p);
38+
WiFiClient available();
39+
void begin(int port);
4140
void begin();
4241
virtual size_t write(uint8_t);
4342
virtual size_t write(const uint8_t *buf, size_t size);
44-
uint8_t status();
43+
void end();
44+
4545

4646
using Print::write;
4747
};

0 commit comments

Comments
 (0)