I found the program on hackster. I wanted to use it. It's kind of like a switch that uses the wifi to turn on a relay. It keeps getting stuck at line 40 with the serial.begin. I checked to make sure I was in the same baud rate. 9600.
This is the original project.
Thanks for your help.
#include <ESP8266WiFi.h>
//Name of the wifi network whom we are supposed to track
const char *SSID = "founder";
const char *pass = "JsxKAA1hELvKpejponx3";
WiFiClient client;
// Relay pin number
int relay=2;
int relay3=0;
// Return RSSI(Received Signal Strength Indicator) or 0 if target SSID not found
int32_t getRSSI(const char* target_ssid) {
byte available_networks = WiFi.scanNetworks();
for (int network = 0; network < available_networks; network++) {
if (WiFi.SSID(network).compareTo(target_ssid) == 0) { //stringOne.compareTo 1(stringTwo) < 0
return WiFi.RSSI(network);
}
}
return 0;
}
void setup() {
Serial.begin(9600);
delay(10);
Serial.println("Connecting to ");
Serial.println(SSID);
WiFi.begin(SSID,pass);
while(WiFi.status() !=WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println(WIFI connected);
int32_t rssi = getRSSI(SSID);
// For debugging purpose only
Serial.print("Signal strength: ");
Serial.print(rssi);
Serial.println(dBm);
pinMode(relay, OUTPUT); // Initialize the relay pin as an output.
pinMode(relay3,OUTPUT);
if (rssi > (-55) && rssi != 0)
digitalWrite(relay,LOW);
delay(750);
digitalWrite(relay,HIGH);
Serial.println(SELF ON);
}
void loop(){
int32_t rssi = getRSSI(SSID);
// For debugging purpose only
Serial.print("Signal strength: ");
Serial.print(rssi);
Serial.println(dBm);
if (rssi > (-55) && rssi != 0) // if rssi is greater then -70 dbm or its 0 dbm, then the light will turn
{
digitalWrite(relay3, LOW);
Serial.println(ON);
}
if (rssi < (-55) && rssi != 0)
{
digitalWrite(relay3,HIGH);
Serial.println(OFF);
}
if(rssi > (-55) && rssi !=0)
{
digitalWrite(relay,LOW);
Serial.println(RELAY ON);
delay(750);
digitalWrite(relay,HIGH);
Serial.println(RELAY OFF);
}
}}
WIFI not declared in scope with the following errors
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved202291-14252-1mf1x94.rrpki\sketch_oct1a\sketch_oct1a.ino: In function 'void setup()':
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved202291-14252-1mf1x94.rrpki\sketch_oct1a\sketch_oct1a.ino:40:16: error: 'WIFI' was not declared in this scope
40 | Serial.println(WIFI connected);
| ^~~~
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved202291-14252-1mf1x94.rrpki\sketch_oct1a\sketch_oct1a.ino:46:16: error: 'dBm' was not declared in this scope
46 | Serial.println(dBm);
| ^~~
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved202291-14252-1mf1x94.rrpki\sketch_oct1a\sketch_oct1a.ino:55:16: error: 'SELF' was not declared in this scope
55 | Serial.println(SELF ON);
| ^~~~
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved202291-14252-1mf1x94.rrpki\sketch_oct1a\sketch_oct1a.ino: In function 'void loop()':
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved202291-14252-1mf1x94.rrpki\sketch_oct1a\sketch_oct1a.ino:64:16: error: 'dBm' was not declared in this scope
64 | Serial.println(dBm);
| ^~~
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved202291-14252-1mf1x94.rrpki\sketch_oct1a\sketch_oct1a.ino:69:16: error: 'ON' was not declared in this scope; did you mean 'OK'?
69 | Serial.println(ON);
| ^~
| OK
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved202291-14252-1mf1x94.rrpki\sketch_oct1a\sketch_oct1a.ino:75:16: error: 'OFF' was not declared in this scope
75 | Serial.println(OFF);
| ^~~
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved202291-14252-1mf1x94.rrpki\sketch_oct1a\sketch_oct1a.ino:80:16: error: 'RELAY' was not declared in this scope
80 | Serial.println(RELAY ON);
| ^~~~~
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved202291-14252-1mf1x94.rrpki\sketch_oct1a\sketch_oct1a.ino:83:21: error: expected ')' before 'OFF'
83 | Serial.println(RELAY OFF);
| ~ ^~~~
| )
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved202291-14252-1mf1x94.rrpki\sketch_oct1a\sketch_oct1a.ino: At global scope:
C:\Users\user\AppData\Local\Temp.arduinoIDE-unsaved202291-14252-1mf1x94.rrpki\sketch_oct1a\sketch_oct1a.ino:85:2: error: expected declaration before '}' token
85 | }}
| ^
exit status 1
Compilation error: 'WIFI' was not declared in this scope