You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems not possible to mix client and server with the WifiShield library / Firmware. Please look at the following code. The Wifi is used as server and check for "GET /alm" request. In this case, the Wifi is used as client to send a Push alert if the time between 2 notifications was passes.
#include<SPI.h>#include<WiFi.h>#include<FlexiTimer2.h>#include<WString.h>#defineNETWORK_SSID "****" // network SSID (name)
#defineNETWORK_PASSWD "***" // network password
#defineKEY_INDEX 0; // network key Index number (needed only for WEP)
#defineLED 13
#defineCYCLE_NB_BETWEEN_NOTIFY 12000;
intstatus=WL_IDLE_STATUS;
WiFiServerserver(80);
WiFiClientalertClient;
voidsetup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
// check for the presence of the shield:if (WiFi.status() ==WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
while(true) {
digitalWrite(LED, HIGH);
delay(125);
digitalWrite(LED, LOW);
delay(125);
}
}
// Set the IP address for the WIFI//WiFi.config(serverIp);// attempt to connect to Wifi network:do {
Serial.print("Attempting to connect to SSID: ");
Serial.println(NETWORK_SSID);
status=WiFi.begin(NETWORK_SSID, NETWORK_PASSWD);
} while ( status!=WL_CONNECTED);
// Start serverserver.begin();
// you're connected now, so print out the status:printWifiStatus();
// Set Timer 2 interrupt
FlexiTimer2::set(5, interruptTimer2);
FlexiTimer2::start(); // active
}
voidloop() {
// Client connectedWiFiClientclient=server.available();
if (client) {
Stringresponse="";
StringcurrentLine=""; // make a String to hold incoming data from the clientSerial.println("new client");
while (client.connected()) {
if (client.available()) {
charc=client.read();
if (c=='\n') { // if the byte is a newline character// Check GET request intind1=currentLine.indexOf("GET /");
if(ind1 >= 0) {
Stringcmd=currentLine.substring(ind1+5, ind1+8);
if (cmd=="alm") {
alertAvailable=true;
}
}
// if the current line is blank, you got two newline characters in a row.// that's the end of the client HTTP request, so send a response:if (currentLine.length() ==0) {
Serial.println("Send response to client.");
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// the content of the HTTP response follows the header:if (response!="") {
client.println(response);
}
// The HTTP response ends with another blank line:client.println();
// break out of the while loop:break;
} else { // if you got a newline, then clear currentLine:currentLine="";
}
} elseif (c!='\r') { // if you got anything else but a cr character,currentLine+=c; // add it to the end of the currentLine
}
}
}
//stopping clientclient.stop();
Serial.println("Client disonnected");
}
// Send alert ?if ((alertAvailable==true) && (timerAlert==0)) {
sendAlert("ALERT+TEST");
}
}
voidinterruptTimer2() {
if (timerAlert>0) {
timerAlert--;
}
}
voidprintWifiStatus() {
// print the SSID of the network you're attached to:Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:IPAddressip=WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:longrssi=WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
voidsendAlert(Stringmessage) {
if (alertClient.connect(alertServerIp, 80)) {
Serial.println("connected to ALERT server");
Serial.println("Send Alert for "+message);
alertClient.println("GET /push/push.php?call=*******&message=+"+message+" HTTP/1.1");
alertClient.println("Host:pautex.fr");
alertClient.println("Connection: close");
alertClient.println();
alertClient.flush();
alertClient.stop();
Serial.println("End Alert for "+message);
alertClient.flush();
}
alertAvailable= false;
timerAlert=CYCLE_NB_BETWEEN_NOTIFY;
}
The server work correctly and send response for any request from my browser until I send the request ip-adress/alm. In this case, the alert is sent (client work correctly). But the server seems to be stopped: The "server.available()" return 0.
The text was updated successfully, but these errors were encountered:
Hello all,
It seems not possible to mix client and server with the WifiShield library / Firmware. Please look at the following code. The Wifi is used as server and check for "GET /alm" request. In this case, the Wifi is used as client to send a Push alert if the time between 2 notifications was passes.
The server work correctly and send response for any request from my browser until I send the request ip-adress/alm. In this case, the alert is sent (client work correctly). But the server seems to be stopped: The "server.available()" return 0.
The text was updated successfully, but these errors were encountered: