Hi,
I am using a wifi shield on the due, I have arduino 1.5.2 running on my system. I am trying to change my ip address using WiFi.config() after WiFi.begin().
However, when I compile I get this error: 'class WiFiClass' has no member named 'config'
I used this link as reference: WiFi - Arduino Reference
I am wondering why I cant use this function when it has been documented. Any help is appreciated.
IPAddress ip(192, 168, 13, 110);
WiFiServer server(80); // create a server at port 80
//-----------------------------------WIFI STUFF--------------------
char ssid[] = "mytestnetwork"; // your network SSID (name)
char pass[] = "somepassword"; // your network password
void setup() {
Serial.begin(9600); // for diagnostics
if (WiFi.status() == WL_NO_SHIELD)
{
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
WiFi.begin(ssid, pass); // initialize WiFi device
Serial.println("test1");
WiFi.config(ip);
delay(10000);
printWifiData();
server.begin(); // start to listen for clients
pinMode(inPin, INPUT);
pinMode(inPin2, INPUT);
pinMode(inPin3, INPUT);
pinMode(motorPin, OUTPUT);
neck.attach(24);
neck.writeMicroseconds(neck_pos_1);
delay(1000);
neck.writeMicroseconds(neck_pos_3);
delay(1000);
//client = server.available(); // try to get client <move this to setup, create it in such a way that in the loop it will ignore if client is already connected>
digitalWrite(motorPin, LOW);
}
#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <Ethernet.h>
WiFiServer server(80);
char ssid[] = "osdevtest"; // your network SSID (name)
char pass[] = "2013cuemedeviceconnect"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
String HTTP_req; // stores the HTTP request
boolean LED_status = 0; // state of LED, off by default
int inPin = 7;
int inPin2 = 8;
int inPin3 = 9;
int val = 0;
int val2 = 0;
int val3 = 0;
int x = 0;
int y = 0;
int z = 0;
IPAddress ip(192, 168, 13, 110);
void setup()
{
//server.begin(); // start to listen for clients
Serial.begin(9600); // for diagnostics
pinMode(2, OUTPUT); // LED on pin 2
pinMode(7, INPUT);
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
Serial.print("You're connected to the network");
printCurrentNet();
printWifiData();
server.begin();
Serial.print("Server started");
WiFi.config(ip);
}
void loop()
{
WiFiClient client = server.available(); // try to get client
if (client) { // got client?
//Serial.print("Got client");
boolean currentLineIsBlank = true;
while (client.connected()) {
//Serial.print("Client connected");
if (client.available()) { // client data available to read
char c = client.read(); // read 1 byte (character) from client
HTTP_req += c; // save the HTTP request 1 char at a time
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
// send web page
client.println("<!DOCTYPE html>");
client.println("<html>");
client.println("<head>");
client.println("<title>Arduino LED Control</title>");
client.println("<meta http-equiv=\"refresh\" content=\"1\">");
client.println("</head>");
client.println("<body>");
client.println("<h1>LED</h1>");
client.println("<p>Click to switch LED on and off.</p>");
client.println("<form method=\"get\">");
ProcessCheckbox(client);
checkMotion(client);
client.println("</form>");
client.println("</body>");
client.println("</html>");
Serial.print(HTTP_req);
HTTP_req = ""; // finished with request, empty string
break;
}
// every line of text received from the client ends with \r\n
if (c == '\n') {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
}
else if (c != '\r') {
// a text character was received from client
currentLineIsBlank = false;
}
} // end if (client.available())
} // end while (client.connected())
delay(1); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)
}
// switch LED and send back HTML for LED checkbox
void ProcessCheckbox(WiFiClient cl)
{
/* if (HTTP_req.indexOf("LED2=2") > -1) { // see if checkbox was clicked
// the checkbox was clicked, toggle the LED
if (LED_status) {
LED_status = 0;
}
else {
LED_status = 1;
}
}*/
if (HTTP_req.indexOf("favicon") > -1){
return;
}
if (HTTP_req.indexOf("LED2=2") > -1) { // see if checkbox was clicked
// the checkbox was clicked, toggle the LED
LED_status = 1;
digitalWrite(2, HIGH);
// checkbox is checked
cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
onclick=\"submit();\" checked>LED2");
cl.println("test1.");
Serial.println("TEST1");
}
else
{
LED_status = 0;
digitalWrite(2, LOW);
// checkbox is unchecked
cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
onclick=\"submit();\">LED2");
cl.println("test2.");
Serial.println("TEST 2");
}
/*if (LED_status) { // switch LED on
digitalWrite(2, HIGH);
// checkbox is checked
cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
onclick=\"submit();\" checked>LED2");
cl.println("test1.");
}
else { // switch LED off
digitalWrite(2, LOW);
// checkbox is unchecked
cl.println("<input type=\"checkbox\" name=\"LED2\" value=\"2\" \
onclick=\"submit();\">LED2");
cl.println("test2.");
}*/
}
void checkPir(WiFiClient c2){
val = digitalRead(inPin);
if ((val == HIGH)||(val2 == HIGH)||(val3 == HIGH))
{
c2.println("<p>Everything is dark, I need thermal vision</p>");
}
else{
c2.println("<p>Who's there? I can see you moving on</p>");
}
Serial.println(val);
Serial.println("***********");
}
void pir1(WiFiClient c3)
{
val = digitalRead(inPin);
if (val == LOW)
{
x=1;
}
else
{
x=0;
}
}
void pir2(WiFiClient c4)
{
val2 = digitalRead(inPin2);
if (val2 == LOW)
{
y=1;
}
else
{
y=0;
}
}
void pir3(WiFiClient c5)
{
val3 = digitalRead(inPin3);
if (val3 == LOW)
{
z=1;
}
else
{
z=0;
}
}
void checkMotion(WiFiClient c6)
{
pir1;
pir2;
pir3;
checkPir(c6);
if (x==1){
c6.println("<p>PIR 1</p>");}
else if (y==1){
c6.println("<p>PIR 2</p>");}
else if (z==1){
c6.println("<p>PIR 3</p>");}
//else{
//c6.println("<p> Y U no work?</p>");}
}
void printWifiData() {
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
Serial.println(ip);
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
Serial.print(mac[5],HEX);
Serial.print(":");
Serial.print(mac[4],HEX);
Serial.print(":");
Serial.print(mac[3],HEX);
Serial.print(":");
Serial.print(mac[2],HEX);
Serial.print(":");
Serial.print(mac[1],HEX);
Serial.print(":");
Serial.println(mac[0],HEX);
}
void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
Serial.print(bssid[5],HEX);
Serial.print(":");
Serial.print(bssid[4],HEX);
Serial.print(":");
Serial.print(bssid[3],HEX);
Serial.print(":");
Serial.print(bssid[2],HEX);
Serial.print(":");
Serial.print(bssid[1],HEX);
Serial.print(":");
Serial.println(bssid[0],HEX);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(rssi);
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type:");
Serial.println(encryption,HEX);
Serial.println();
}
Error Message is:
test_wifi_using_http_server.ino: In function ‘void setup()’:
test_wifi_using_http_server:55: error: ‘class WiFiClass’ has no member named ‘config’
Why do you assume that the WiFiClass does have a member named config? It does in 1.5.5, but that may not be true in 1.5.2. My version of 1.5.2 doesn't even have a WiFi library.