What's Wrong With This Code?
Posted: Tue Jan 12, 2016 1:34 pm
It is not printing to the serial monitor, nor toggling pin 2 on and off!
Why is that?
The code:
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);
}
}