error: 'WiFiServer' does not name a type

on an Arduino Uno Wifi

Using Arduinowifi.h and launching a web service with WiFiServer server(8899);

I got this message when compiled : error: 'WiFiServer' does not name a type

it compiles very well with wifi.h

any idea ?

Show your code (using code tags)

type
** **[code]** **

paste your code after that
type
** **[/code]** **
after that

I don't have the Header file you mention but it would appear that ArduinoWiFi.h does not define the same class as WiFi.h. That would be Logical as well.

So, if the one Header doesn't define that class, you have to Change your sketch to use the class which is defined.

#include <Wire.h>
#include <ArduinoWiFi.h>

const char *gpsStream =
  "$GPRMC,045103.000,A,3014.1984,N,09749.2872,W,0.67,161.46,030913,,,A*7C\r\n";

char CSSentence[85] = "" ; //string for sentence assembly
char NMEASentence[85] = "" ; //string for NMEA sentence
int cs ; //checksum

// telnet defaults to port 8899
WiFiServer server(8899);

void setup()
{
// initialize the wifi device
WiFi.begin();
// start listening for clients
Server.begin();
}

// ////////////////////// Functions ////////////////////////////////////


String Checksum(char* CSSentence) {
cs=0; //clear any old checksum
char b[50]="0";
//return b;

for (int n=0; n < strlen(CSSentence); n++) {
cs ^= CSSentence[n]; //calculates the checksum
}
sprintf(b,"%02X",cs);
return b;
}

void WiFiNMEA (char* NMEASentence) {
server.print(NMEASentence);
server.println();
}

// ////////////////////// Loop ////////////////////////////////////

void loop()
{
// if an incoming client connects, there will be bytes available to read:
 WiFiClient client = server.available();
  if (client == true) {
       // send bytes 
    // to any clients connected to the server:
   WiFiNMEA(gpsStream);
   delay (300);
  }
}
#include <ArduinoWiFi.h>

A link to that library would be essential.

Why do you assume that the class defined in that library is also called WiFiServer? The naming convention would suggest that that is an invalid assumption.

it was the case with the previous wifi.h used with the wifi shield for uno

It's not the same library, so you may not assume that it supports the same classes and methods.

By the way, it's a library from arduino.org, so you might get better support at their forums.

i have got the same error and here is my code

#include<LiquidCrystal.h>
#include <SerialESP8266wifi.h>
const char* ssid = "Zunik Energies Pvt Ltd";
const char* password = "zunik1234";
unsigned char status_led=0;
WiFiServer server(80);

#include<SoftwareSerial.h>
#include <EmonLib.h>

SoftwareSerial ESP8266(2,3);
EnergyMonitor emon1;
String myAPIkey = "4K393TQPJXHX84VQ";
LiquidCrystal lcd(12,11,5,4,3,2);
double RMS_Voltage,RMS_current,Power_Factor,Active_Power,Apparent_Power;
long writingTimer = 17;
long startTime = 0;
long waitTime = 0;
boolean relay1_st = false;
boolean relay2_st = false;
unsigned char check_connection=0;
unsigned char times_check=0;
boolean error;

void setup()
{
Serial.begin(115200);
lcd.begin(20,4);
lcd.clear();
emon1.voltage(2,2313.26,1.7);
emon1.current(1,58.1);
startTime = millis();
Serial.println("AT+RST");
delay(2000);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
server.begin();
Serial.println("Server started");
Serial.println(WiFi.localIP());

Serial.println("Connecting to Wifi");
while(check_connection==0)
{
Serial.print(".");
Serial.print("AT+CWJAP="manasadevi123","Life@105"\r\n");
Serial.setTimeout(5000);
if(Serial.find("Wifi CONNECTED\r\n")==1)
{
Serial.println("WIFI CONNECTED");
break;
}
times_check++;
if(times_check>3)
{
int time_check=0;
Serial.println("Trying to Reconnect..") ;
}
}
}
void loop()
{
emon1.calcVI(20,2000);
emon1.serialprint();
unsigned int long timemillis = millis();
unsigned int long time =timemillis/1000;
float realPower = emon1.realPower;
float apparentPower = emon1.apparentPower;
float supplyVoltage = emon1.Vrms;
float Irms = emon1.Irms;
float powerFactor = (realPower/ apparentPower);
waitTime = millis()-startTime;
if (waitTime > (writingTimer1000))
{
float readSensors(float Vrms,float Irms,float apparentPower,float activePower,float Powerfactor);
writeThingSpeak();
startTime = millis();
}
lcd.setCursor(4,0);
lcd.print ("EnergyMonitor");
lcd.setCursor(0,1);
lcd.print("V = ");
lcd.print (supplyVoltage);
lcd.setCursor(9,1);
lcd.print("I = ");
lcd.print(Irms);
lcd.setCursor(0,2);
lcd.print("Powerfactor = ");
lcd.print(powerFactor);
lcd.setCursor(0,3);
lcd.print("Units(kWh) = ");
lcd.print(abs(realPower
time)/abs(1000*3600));
}
void readSensors(double voltage_rms,double current_rms,double power_factor,double active_power,double apparent_power)
{
float RMS_voltage=voltage_rms;
float RMS_current=current_rms;
float Power_Factor=power_factor;
float Apparent_Power=apparent_power;
float Active_Power=active_power;
}
void writeThingSpeak(void)
{
startThingSpeakCmd();
String getStr = "GET /update?api_key=";
getStr += myAPIkey;
getStr +="&field1=";
getStr += String(RMS_Voltage);
getStr +="&field2=";
getStr += String(RMS_current);
getStr +="&field2=";
getStr += String(Power_Factor);
getStr +="&field2=";
getStr += String(Active_Power);
getStr +="&field2=";
getStr += String(Apparent_Power);
getStr +="\r\n\r\n";
}

void startThingSpeakCmd(void)
{
Serial.flush();
String cmd = "AT+CIPSTART="TCP","";
cmd += "184.106.153.149";//api. thingspeak.com IP address
cmd += "",80";
Serial.println(cmd);
Serial.print("Start Commands: ");
Serial.print(cmd);

if(Serial.find("Error"))
{
Serial.println("AT+CIPSTART error");
return;
}
}
String GetThingspeakcmd(String getStr)
{
String cmd = "AT+CIPSTART=";
cmd += String(getStr.length());
Serial.println(cmd);
Serial.println(cmd);

if(Serial.find(">"))
{
Serial.print(getStr);

delay(500);
String messageBody = "";
while (Serial.available())
{
String line = Serial.readStringUntil('\n');
if (line.length() == 1)
{
messageBody = Serial.readStringUntil('\n');
}
}
Serial.print("MessageBody received: ");
Serial.println(messageBody);
return messageBody;
}
else
{
Serial.println("AT+CIPCLOSE");
Serial.println("AT+CIPCLOSE");
}
WiFiClient client = server.available();

Serial.println("new client");
while(!client.available())
{
delay(1);
}
String req = client.readStringUntil('\r');
Serial.println(req);
}

Look at the examples that come with the wifi library you're using. The declaration part looks like this:

SoftwareSerial swSerial(sw_serial_rx_pin, sw_serial_tx_pin);

// the last parameter sets the local echo option for the ESP8266 module..
SerialESP8266wifi wifi(Serial, Serial, esp8266_reset_pin, swSerial);

i tried a lot to resolve this but ended up with the same error.. something is wrong in my code and i am unable to understand it.. help me out if you can.. thanks a lot for responding.

Post your latest attempt. In code tags please.

give your mail-id or whatever social media you use. you can give your whats app number if you are comfortable to share with me. so that i will let you know my every attempt .

check out, this is my code and i have made previous modifications. i feel glad if you can sort out error.

#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <EmonLib.h>
EnergyMonitor emon1;
String myAPIkey = "RN2KJCMHBA25IQQ7";
SoftwareSerial ESP8266(6,9);
const int rs=12,en=11,d4=5,d5=4,d6=3,d7=2;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);

double Average_Voltage,Average_Current,RMS_Voltage,RMS_Current,Power_Factor,Active_Power,Reactive_Power,Apparent_Power;
long writingTimer = 17;
long startTime = 0;
long waitTime = 0;

boolean relay1_st = false;
boolean relay2_st = false;
unsigned char check_connection=0;
unsigned char times_check=0;
boolean error;

void setup() {
Serial.begin(9600);

emon1.voltage(2,234.26,1.7);
emon1.current(1,111.1);
lcd.begin(20,4);
lcd.clear();
ESP8266.begin(9600);
startTime = millis();
ESP8266.println("AT+RST");
delay(2000);
Serial.println("Connecting to Wifi");
while(check_connection==0)
{
Serial.print(".");
ESP8266.print("AT+CWJAP="Subham","123456789"\r\n");
ESP8266.setTimeout(5000);
if(ESP8266.find("WIFI CONNECTED\r\n")==1)
{
Serial.println("WIFI CONNECTED");
break;
}
times_check++;
if(times_check>3)
{
times_check=0;
Serial.println("Trying to Reconnect..");
}
}

// put your setup code here, to run once:

}

void loop() {
emon1.calcVI(20,2000);
emon1.serialprint();
unsigned int long timemillis=millis();
unsigned int long time=timemillis/1000;
float realPower = emon1.realPower;
float apparentPower = emon1.apparentPower;
float powerFactor = emon1.powerFactor;
float supplyVoltage = emon1.Vrms;
float Irms = emon1.Irms;
float Vavg=supplyVoltage0.45;
float Iavg=Irms
0.45;
float reactivePower=apparentPower*sin(acos(powerFactor));

waitTime = millis()-startTime;
if (waitTime > (writingTimer*1000))
{
readSensors(supplyVoltage,Vavg,Irms,Iavg,powerFactor,realPower,reactivePower,apparentPower);
writeThingSpeak();
startTime = millis();
}

lcd.setCursor(0,0);
lcd.print("Vav=");
lcd.print(Vavg);
lcd.setCursor(11,0);
lcd.print("Iav=");
lcd.print(Iavg);
lcd.setCursor(0,1);
lcd.print("V=");
lcd.print(supplyVoltage);
lcd.setCursor(9,1);
lcd.print("I=");
lcd.print(Irms);
lcd.setCursor(0,2);
lcd.print("Pf=");
lcd.print(powerFactor);
lcd.setCursor(9,2);
lcd.print("Pr=");
lcd.print(reactivePower);
lcd.setCursor(0,3);
lcd.print("Units(kWh)=");
lcd.print(abs(realPowertime)/abs(10003600));
// put your main code here, to run repeatedly:

}

void readSensors(double voltage_rms,double voltage_avg,double current_rms,double current_avg,double power_factor,double active_power,double reactive_power,double apparent_power)
{
Average_Voltage=voltage_avg;
Average_Current=current_avg;
RMS_Voltage=voltage_rms;
RMS_Current=current_rms;

Power_Factor=power_factor;
Active_Power=active_power;
Reactive_Power=reactive_power;
Apparent_Power=apparent_power;
}

void writeThingSpeak(void)
{
startThingSpeakCmd();
// preparacao da string GET
String getStr = "GET /update?api_key=";
getStr += myAPIkey;
getStr +="&field1=";
getStr += String(Average_Voltage);
getStr +="&field2=";
getStr += String(Average_Current);
getStr +="&field2=";
getStr += String(RMS_Voltage);
getStr +="&field2=";
getStr += String(RMS_Current);
getStr +="&field2=";
getStr += String(Power_Factor);
getStr +="&field2=";
getStr += String(Active_Power);
getStr +="&field2=";
getStr += String(Reactive_Power);
getStr +="&field2=";
getStr += String(Apparent_Power);
getStr += "\r\n\r\n";
GetThingspeakcmd(getStr);
}

void startThingSpeakCmd(void)
{
ESP8266.flush();
String cmd = "AT+CIPSTART="TCP","";
cmd += "184.106.153.149"; // api.thingspeak.com IP address
cmd += "",80";
ESP8266.println(cmd);
Serial.print("Start Commands: ");
Serial.println(cmd);

if(ESP8266.find("Error"))
{
Serial.println("AT+CIPSTART error");
return;
}
}

String GetThingspeakcmd(String getStr)
{
String cmd = "AT+CIPSEND=";
cmd += String(getStr.length());
ESP8266.println(cmd);
Serial.println(cmd);

if(ESP8266.find(">"))
{
ESP8266.print(getStr);
Serial.println(getStr);
delay(500);
String messageBody = "";
while (ESP8266.available())
{
String line = ESP8266.readStringUntil('\n');
if (line.length() == 1)
{
messageBody = ESP8266.readStringUntil('\n');
}
}
Serial.print("MessageBody received: ");
Serial.println(messageBody);
return messageBody;
}
else
{
ESP8266.println("AT+CIPCLOSE");
Serial.println("AT+CIPCLOSE");
}
}