As the title says I am trying to use the wifi module by importing arduino’s WiFi101 library. The problem is that I am getting a lot if weird import errors, where the compiler is highlighting things that should have been already imported when writing #include<WiFi101.h>. Furthermore I am getting an error at the library lever, more precisely in the WiFiServer.h file line 31 2h3n talking about the socket.
This runs with no problem on the Arduino IDE.
this is the code I a trying to run.
#ifndef WIFI_H
#define WIFI_H
#include <Arduino.h>
#include <WiFi101.h>
#define WINC_CS 8
#define WINC_IRQ 7
#define WINC_RST 4
#define WINC_EN 2
// Feather M0 WiFi (WINC1500) pins
//const int WINC_CS = 8, WINC_IRQ = 7, WINC_RST = 4, WINC_EN = 2;
const char ssid[] = "FeatherAP";
const char pass[] = "test1234"; // >= 8 chars for WPA2
String ipToString(const IPAddress& ip) {
return String(ip[0]) + "." + String(ip[1]) + "." + String(ip[2]) + "." + String(ip[3]);
}
void handleRoot(WiFiClient& client){
// Minimal well-formed HTTP response
const char body[] = "Initial Page";
client.print("HTTP/1.1 200 OK\r\n");
client.print("Content-Type: text/html\r\n");
client.print("Connection: close\r\n");
client.print("Content-Length: "); client.print(sizeof(body) - 1); client.print("\r\n\r\n");
client.print(body);
delay(1);
}
void handleForward(WiFiClient& client){
moveForward();
// Minimal well-formed HTTP response
const char body[] = "Moved Forward";
client.print("HTTP/1.1 200 OK\r\n");
client.print("Content-Type: text/html\r\n");
client.print("Connection: close\r\n");
client.print("Content-Length: "); client.print(sizeof(body) - 1); client.print("\r\n\r\n");
client.print(body);
delay(1);
}
void handleBackward(WiFiClient& client){
moveBackward();
// Minimal well-formed HTTP response
const char body[] = "Moved Backward";
client.print("HTTP/1.1 200 OK\r\n");
client.print("Content-Type: text/html\r\n");
client.print("Connection: close\r\n");
client.print("Content-Length: "); client.print(sizeof(body) - 1); client.print("\r\n\r\n");
client.print(body);
delay(1);
}
void handleMoveLeft(WiFiClient& client){
moveLeft();
// Minimal well-formed HTTP response
const char body[] = "Moved Left";
client.print("HTTP/1.1 200 OK\r\n");
client.print("Content-Type: text/html\r\n");
client.print("Connection: close\r\n");
client.print("Content-Length: "); client.print(sizeof(body) - 1); client.print("\r\n\r\n");
client.print(body);
delay(1);
}
void handleMoveRight(WiFiClient& client){
moveRight();
// Minimal well-formed HTTP response
const char body[] = "Moved Right";
client.print("HTTP/1.1 200 OK\r\n");
client.print("Content-Type: text/html\r\n");
client.print("Connection: close\r\n");
client.print("Content-Length: "); client.print(sizeof(body) - 1); client.print("\r\n\r\n");
client.print(body);
delay(1);
}
void handleTurnRight(WiFiClient& client){
turnRight();
// Minimal well-formed HTTP response
const char body[] = "Turned Right";
client.print("HTTP/1.1 200 OK\r\n");
client.print("Content-Type: text/html\r\n");
client.print("Connection: close\r\n");
client.print("Content-Length: "); client.print(sizeof(body) - 1); client.print("\r\n\r\n");
client.print(body);
delay(1);
}
void handleTurnLeft(WiFiClient& client){
turnLeft();
// Minimal well-formed HTTP response
const char body[] = "Turned Left";
client.print("HTTP/1.1 200 OK\r\n");
client.print("Content-Type: text/html\r\n");
client.print("Connection: close\r\n");
client.print("Content-Length: "); client.print(sizeof(body) - 1); client.print("\r\n\r\n");
client.print(body);
delay(1);
}
void handleStop(WiFiClient& client){
stopAllMotors();
// Minimal well-formed HTTP response
const char body[] = "Stopped all motors";
client.print("HTTP/1.1 200 OK\r\n");
client.print("Content-Type: text/html\r\n");
client.print("Connection: close\r\n");
client.print("Content-Length: "); client.print(sizeof(body) - 1); client.print("\r\n\r\n");
client.print(body);
delay(1);
}
void route(WiFiClient& c,const String& path,const String& q){
if(path=="/"||path=="") { handleRoot(c); return; }
if(path=="/f") { handleForward(c); return; }
if(path=="/b") { handleBackward(c); return; }
if(path=="/ml") { handleMoveLeft(c); return; }
if(path=="/mr") { handleMoveRight(c); return; }
if(path=="/tr") { handleTurnRight(c); return; }
if(path=="/tl") { handleTurnLeft(c); return; }
if(path=="/stop") { handleStop(c); return; }
// sendText(c,"404\n");
}
void serve(WiFiClient& c){
c.setTimeout(1500);
String rl=c.readStringUntil('\n'); // "GET /path?query HTTP/1.1"
int sp1=rl.indexOf(' '), sp2=rl.indexOf(' ',sp1+1);
String uri=(sp1>0&&sp2>sp1)?rl.substring(sp1+1,sp2):"/";
int q=uri.indexOf('?'); String pth=(q>=0)?uri.substring(0,q):uri; String qry=(q>=0)?uri.substring(q+1):"";
while(true){ String h=c.readStringUntil('\n'); if(h.length()==0||h=="\r") break; } // headers
route(c,pth,qry);
}
void wifiSetup(){
WiFiServer server(80);
WiFi.setPins(WINC_CS, WINC_IRQ, WINC_RST, WINC_EN);
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WINC1500 not detected"); while (1) {}
}
Serial.print("FW: "); Serial.println(WiFi.firmwareVersion());
Serial.println("Starting AP…");
int s = WiFi.beginAP(ssid, pass, 6); // WPA2, ch 6
if (s != WL_AP_LISTENING) {
Serial.print("WPA2 AP failed ("); Serial.print(s); Serial.println("). Trying OPEN…");
s = WiFi.beginAP(ssid, 6); // OPEN AP fallback
if (s != WL_AP_LISTENING) { Serial.println("AP failed"); while (1) {} }
}
delay(8000); // let AP + DHCP come up
Serial.print("AP IP: "); Serial.println(ipToString(WiFi.localIP())); // usually 192.168.1.1
}
#endif