Skip to content

Instantly share code, notes, and snippets.

@kasperkamperman
Last active July 14, 2016 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasperkamperman/77d9c941f07ac05e78e4d400c96e5113 to your computer and use it in GitHub Desktop.
Save kasperkamperman/77d9c941f07ac05e78e4d400c96e5113 to your computer and use it in GitHub Desktop.
Strongest SSID example crash
/*
This will give a hard fault firmware crash.
The crash can be prevented by adding a delay of around 800ms (I've tested 100ms and 500ms and it crashes the same).
*/
#include "application.h"
//SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(MANUAL);
class FindStrongestSSID
{
char strongest_ssid[33];
int strongest_rssi;
// This is the callback passed to WiFi.scan()
// It makes the call on the `self` instance - to go from a static
// member function to an instance member function.
static void handle_ap(WiFiAccessPoint* wap, FindStrongestSSID* self)
{
self->next(*wap);
}
// determine if this AP is stronger than the strongest seen so far
void next(WiFiAccessPoint& ap)
{
if ((ap.rssi < 0) && (ap.rssi > strongest_rssi)) {
strongest_rssi = ap.rssi;
strcpy(strongest_ssid, ap.ssid);
}
}
public:
/**
* Scan Wi-Fi Access Points and retrieve the strongest one.
*/
const char* scan()
{
// initialize data
strongest_rssi = 0;
strongest_ssid[0] = 0;
// perform the scan
WiFi.scan(handle_ap, this);
return strongest_ssid;
}
};
// Now use the class
FindStrongestSSID strongestFinder;
const char* ssid;
void setup() {
Serial.begin(57600);
delay(5000);
Serial.println("hi");
Particle.connect();
Serial.println("hi again");
// adding a delay to the end seems to solve the crash
//delay(800);
}
void loop() {
ssid = strongestFinder.scan();
//Serial.print("strongest ssid : ");
//Serial.println(ssid);
//delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment