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

Moderator: igrr

User avatar
By danbicks
#32479
derek bernsen wrote:Ok. I think I've fixed it. No error messages with the code anymore. I'll upload the code to my ESP-01 or maybe my ESP-201 module for initial testing later.


Instead of messing with varying the PWM period based on RSSI, why not go with a simple method of 1 beep per second far away 4 beeps very near etc, this way you could use simple logic based on RSSI to determine amount of beeps required.

A simple solution.

Hope this helps

Dans

PS: Take a look at my wifi scan and acquire routine sometime ago, this also incorporates an OLED, would be cool to have visual display on this.

Dans
User avatar
By derek bernsen
#32498 Thanks for the idea!

This has been tested, but only blinks every 4 seconds or so, or is full on, so not a range of blink rates. No idea why:
Code: Select all#include <Arduino.h>
#include <ESP8266WiFi.h>

int buzzerPin = 2;
int buzzerState = LOW;



const char* SSID = "belkin.d4c";

// 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(buzzerPin, OUTPUT);
}

void loop() {
  unsigned long before = millis();
  int32_t rssi = getRSSI(SSID);
  int result = (rssi + 33) * -15;
  // int result = rssi * -7.7;
  unsigned long after = millis();
 
 
 digitalWrite(buzzerPin, HIGH);
 delay(result);
 digitalWrite(buzzerPin, LOW);
 
 
 //(rssi * -7.7)
 
 } 




Here's the second program I tried, it works as a non-blinking meter, it emits a constant tone that increases in volume when I go closer to the beacon:
Code: Select all#include <Arduino.h>
#include <ESP8266WiFi.h>

int buzzerPin = 2;
int buzzerState = LOW;



const char* SSID = "belkin.d4c";

// 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(buzzerPin, OUTPUT);
}

void loop() {
  unsigned long before = millis();
  int32_t rssi = getRSSI(SSID);
  int result = (rssi + 33) * -15;
  unsigned long after = millis();
  int volume = (rssi + 33) * -15;

  analogWrite(2, volume);
}


I am using a nearby WiFi router as the AP to test, I'll use the beacon later on.