Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By derek bernsen
#38603 It is not printing to the serial monitor, nor toggling pin 2 on and off!
Why is that?

The code:
Code: Select all#include <Arduino.h>
#include <ESP8266WiFi.h>

int OptoPin = 2;

 const char* SSID = "AI-THINKER_F53A7F";
// Return RSSI 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 (strcmp(WiFi.SSID(network), target_ssid) == 0) {
      return WiFi.RSSI(network);
    }
  }
  return 0;
}

void setup() {
  Serial.begin(115200);
  pinMode(OptoPin, OUTPUT);
}

void loop() {
  int32_t rssi = getRSSI(SSID);
  //int result = (rssi) * (rssi);
  int result = rssi * rssi;
   //int output = rssi;
   Serial.print(result);
  if (result > 80) {
   digitalWrite(2, HIGH);
   delay(10);
   }
  else if (result < 80) {
   digitalWrite(2, LOW);
   
  }
}
 
User avatar
By martinayotte
#38607 First, is the SSID "AI-THINKER_F53A7F" is the one from the current ESP or one from another ESP ?
Because, the current ESP won't be in the list of scanNetworks(), it doesn't scan itself.
Also, scanNetwork() probably returns nothing if your ESP is in AP-only mode, you need to do either WiFi.mode(WIFI_AP_STA); or WiFi.mode(WIFI_STA); to be able to scan APs.
User avatar
By reaper7
#38653 ...and finally if you have arduino esp8266 github version with sdk 1.5.x then:
https://github.com/esp8266/Arduino/issues/1355
User avatar
By derek bernsen
#38720 I fixed the scan networks. I made it faster by connecting to a network instead of scanning for it first.
Serial printing is working fine...
However, the LED (optoisolator) on GPIO2 is still not responding.
Why is GPIO2 not working? it goes to the LED, then to 3.3v positive.
There is a current limiting resistor between GPIO2 and LED - color coded brown-black-yellow-gold.
I am using a ESP-01 module that connects to a WiFi hotspot.
Here's my current code:
Code: Select all#include <ESP8266WiFi.h>
#include <SPI.h> //Not sure if needed for serial printing.
const char* ssid     = "dd-wrt_vap"; //AP
const char* password = ""; //Left blank, open hotspot.

void setup(){
     Serial.begin(115200);
     WiFi.mode(WIFI_STA);
     WiFi.begin(ssid, password);
}

 void loop() {
   
    if (WiFi.status() != WL_CONNECTED) {
    Serial.println("Couldn't get a wifi connection");
    digitalWrite(2, HIGH);
    Serial.println("OPTO OFF");
   
    }
  else {

  long rssi = WiFi.RSSI();
  Serial.print(rssi);
   
  if (rssi > -80 && rssi < 0) {
   digitalWrite(2, LOW);
   Serial.println("OPTO ON");
   }
   
  if (rssi < -80) {
   digitalWrite(2, HIGH);
   Serial.println("OPTO OFF");
   
  }
  }
 }