Print.ln error in a program

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

The sketch is full of problems

Serial.println(RELAY ON);
delay(750);
digitalWrite(relay,HIGH);
Serial.println(RELAY OFF);
Serial.println(WIFI connected);
Serial.println(dBm);
Serial.println(SELF ON);
Serial.println(ON);
Serial.println(OFF);

No quotes round text

Then at the end of the sketch you have too many closing braces

this is syntax error, this means this code has never been tested by the person who posted it, that means you should probably not use it.

It needs quotes the least

Serial.println("WIFI connected");

Thank you UKHeliBob and killzone_kid. Never done this before I'm usually turning wrenches on the motorcycle but I liked the idea of it. Let me add some quotes and see what happens.

Don't forget to remove the extra brace at the end of the code

Even if the code compiles it may still not do what you want, or indeed do anything at all

I'm using Arduino IDE on a Windows 11 64 bit Asus Zenbook Pro (UX531) trying to upload to a Adafruit Feather HUZZAH ESP8266. Sorry I forgot to mention that in case its a hardware issue. I uploaded the ESP8266 libraries to Arduino IDE before looking at this code.

  • The Verify step worked after adding the quotations to print.ln starting on line 40
  • The Upload step to the ESP8266 failed at esptool.py

Could that be my ESP8266 libraries?

I've uninstalled the Arduino IDE twice already. A third time wouldn't be a big deal. I did try it again from COM 4 instead of COM 3 after restarting just in case it was a connection issue. Same ESPtool.py error. Any help in getting this uploaded. Even if, it might not work as intended. :smiley:

Will at least be a dry run for finding code that does work eventually. Wish there was a way to just buy a tested program that does the thing. Haha. I want to turn on the WIFI function, connect to my motorcycle, within range of the ESP8266 WIFI function it turns on the relay for a short period that turns the ignition wire to the starter. That's really all I wanted I guess the RFID gadget route would have been much easier but I have a purpose! This will work one day. :smiley:

#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.println(".");
}
Serial.println("");
Serial.println("WIFI connected");
int32_t rssi = getRSSI(SSID);

// For debugging purpose only
Serial.println("Signal strength: ");
Serial.println("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.println("Signal strength: ");
Serial.println("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");
}
}

Executable segment sizes:

ICACHE : 32768 - flash instruction cache

IROM : 246276 - code in flash (default or ICACHE_FLASH_ATTR)

IRAM : 27273 / 32768 - code in IRAM (IRAM_ATTR, ISRs...)

DATA : 1508 ) - initialized variables (global, static) in RAM/HEAP

RODATA : 1068 ) / 81920 - constants (global, static) in RAM/HEAP

BSS : 25808 ) - zeroed variables (global, static) in RAM/HEAP

Sketch uses 276125 bytes (26%) of program storage space. Maximum is 1044464 bytes.
Global variables use 28384 bytes (34%) of dynamic memory, leaving 53536 bytes for local variables. Maximum is 81920 bytes.
esptool.py v3.0
Serial port COM4
Connecting...
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.2/tools/upload.py", line 66, in
esptool.main(cmdline)
File "C:/Users/user/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool\esptool.py", line 3552, in main
esp.connect(args.before, args.connect_attempts)
File "C:/Users/user/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool\esptool.py", line 519, in connect
last_error = self._connect_attempt(mode=mode, esp32r0_delay=False)
File "C:/Users/user/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool\esptool.py", line 499, in _connect_attempt
self.sync()
File "C:/Users/user/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool\esptool.py", line 438, in sync
timeout=SYNC_TIMEOUT)
File "C:/Users/user/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool\esptool.py", line 376, in command
self.write(pkt)
File "C:/Users/user/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool\esptool.py", line 339, in write
self._port.write(buf)
File "C:/Users/user/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/pyserial\serial\serialwin32.py", line 325, in write
raise SerialTimeoutException('Write timeout')
serial.serialutil.SerialTimeoutException: Write timeout
Failed uploading: uploading error: exit status 1

Well, you could pay someone to write it for you. There is even a section of the forum where you can look for someone to do it, but I suspect that you are not serious

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.