Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/esp32.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: esp32
on: [push, pull_request]
on: [push, pull_request, workflow_dispatch]
jobs:
build:
name: Test compile examples for esp32
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Checkout Arduino-List
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: davidchatting/Arduino-List
ref: master
Expand All @@ -21,5 +21,6 @@ jobs:
with:
arduino-board-fqbn: esp32:esp32:esp32
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
arduino-platform: esp32:esp32
extra-arduino-cli-args: "--warnings default"
required-libraries: ArduinoJson,StreamUtils,PubSubClient,AceButton
6 changes: 3 additions & 3 deletions .github/workflows/esp8266.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: esp8266
on: [push, pull_request]
on: [push, pull_request, workflow_dispatch]
jobs:
build:
name: Test compile examples for esp8266
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Checkout Arduino-List
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
repository: davidchatting/Arduino-List
ref: master
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
.vscode/
.pio/
test/
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 David Chatting - github.com/davidchatting/Approximate
Copyright (c) 2020-2026 David Chatting - github.com/davidchatting/Approximate

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
235 changes: 225 additions & 10 deletions README.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions examples/CloseBy/CloseBy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Approximate approx;
const int LED_PIN = 2;
#endif

void onProximateDevice(Device *device, Approximate::DeviceEvent event);

void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
Expand Down
2 changes: 2 additions & 0 deletions examples/CloseByMQTT/CloseByMQTT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ PubSubClient mqttClient(wifiClient);
const int LED_PIN = 2;
#endif

void onProximateDevice(Device *device, Approximate::DeviceEvent event);

void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
Expand Down
5 changes: 5 additions & 0 deletions examples/CloseBySonoff/CloseBySonoff.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ using namespace ace_button;

Device *closeBySonoff = NULL;

void onProximateDevice(Device *device, Approximate::DeviceEvent event);
void onCloseBySonoff(Device *device, Approximate::DeviceEvent event);
void onButtonEvent(AceButton* button, uint8_t eventType, uint8_t buttonState);
void switchCloseBySonoff(bool switchState);

void setup() {
Serial.begin(9600);

Expand Down
77 changes: 77 additions & 0 deletions examples/DeviceFilter/DeviceFilter.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Device Filter example for the Approximate Library
-
Filter active devices by OUI (Organizationally Unique Identifier) to detect
specific manufacturer devices on the network. Demonstrates addActiveDeviceFilter
and removeActiveDeviceFilter with OUI-based filtering.
-
Common OUIs (see http://standards-oui.ieee.org/oui.txt):
0xD8F15B Sonoff (Espressif)
0xA4CF12 Espressif
0x3C71BF Espressif
0xDCA632 Apple
0x98E743 Apple
-
David Chatting - github.com/davidchatting/Approximate
MIT License - Copyright (c) February 2021, Updated 2026
*/

#include <Approximate.h>
Approximate approx;

// Define for your board, not all have built-in LED:
#if defined(ESP8266)
const int LED_PIN = 14;
#elif defined(ESP32)
const int LED_PIN = 2;
#endif

void onActiveDevice(Device *device, Approximate::DeviceEvent event);

void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);

if (approx.init("MyHomeWiFi", "password")) {
// Filter for Espressif devices by OUI
approx.addActiveDeviceFilter(0xA4CF12);
approx.addActiveDeviceFilter(0x3C71BF);
approx.addActiveDeviceFilter(0xD8F15B);

approx.setActiveDeviceHandler(onActiveDevice);
approx.begin();
}
}

void loop() {
approx.loop();
}

void onActiveDevice(Device *device, Approximate::DeviceEvent event) {
switch (event) {
case Approximate::SEND:
digitalWrite(LED_PIN, HIGH);
Serial.printf("SEND\t%s\tOUI: 0x%06X\tRSSI: %i\t%i bytes\n",
device->getMacAddressAsString().c_str(),
device->getOUI(),
device->getRSSI(),
device->getPayloadSizeBytes());
break;
case Approximate::RECEIVE:
digitalWrite(LED_PIN, LOW);
Serial.printf("RECV\t%s\tOUI: 0x%06X\tRSSI: %i\t%i bytes\n",
device->getMacAddressAsString().c_str(),
device->getOUI(),
device->getRSSI(),
device->getPayloadSizeBytes());
break;
case Approximate::PROBE:
Serial.printf("PROBE\t%s\tOUI: 0x%06X\tRSSI: %i\n",
device->getMacAddressAsString().c_str(),
device->getOUI(),
device->getRSSI());
break;
default:
break;
}
}
2 changes: 2 additions & 0 deletions examples/FindMy/FindMy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ bool ledState = LOW;
long ledToggleAtMs = 0;
int ledToggleIntervalMs = 0;

void onActiveDevice(Device *device, Approximate::DeviceEvent event);

void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
Expand Down
2 changes: 2 additions & 0 deletions examples/MonitorCSI/MonitorCSI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <Approximate.h>
Approximate approx;

void onChannelStateEvent(Channel *channel);

void setup() {
Serial.begin(9600);

Expand Down
49 changes: 49 additions & 0 deletions examples/ProbeDetect/ProbeDetect.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Probe Detect example for the Approximate Library
-
Detect nearby devices via WiFi management frames (probe requests, beacons)
without requiring a WiFi connection or IP address resolution.
Demonstrates the PROBE event introduced in v2.0.
-
David Chatting - github.com/davidchatting/Approximate
MIT License - Copyright (c) February 2021, Updated 2026
*/

#include <Approximate.h>
Approximate approx;

void onProximateDevice(Device *device, Approximate::DeviceEvent event);

void setup() {
Serial.begin(9600);

// init with no IP resolution (false) - PROBE events don't need it
if (approx.init("MyHomeWiFi", "password", false)) {
approx.setProximateDeviceHandler(onProximateDevice, APPROXIMATE_PERSONAL_RSSI);
approx.begin();
}
}

void loop() {
approx.loop();
}

void onProximateDevice(Device *device, Approximate::DeviceEvent event) {
switch (event) {
case Approximate::ARRIVE:
Serial.printf("ARRIVE\t%s\tOUI: 0x%06X\tRSSI: %i\n",
device->getMacAddressAsString().c_str(),
device->getOUI(),
device->getRSSI());
break;
case Approximate::DEPART:
Serial.printf("DEPART\t%s\n",
device->getMacAddressAsString().c_str());
break;
case Approximate::PROBE:
Serial.printf("PROBE\t%s\tRSSI: %i\n",
device->getMacAddressAsString().c_str(),
device->getRSSI());
break;
}
}
71 changes: 71 additions & 0 deletions examples/ProximityZones/ProximityZones.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Proximity Zones example for the Approximate Library
-
Classify nearby devices into proximity zones based on RSSI signal strength:
INTIMATE (< 0.5m) RSSI > -20
PERSONAL (0.5-1.5m) RSSI > -40
SOCIAL (1.5-3m) RSSI > -60
PUBLIC (3-5m) RSSI > -80
-
Demonstrates setProximateRSSIThreshold, setProximateLastSeenTimeoutMs,
and the RSSI threshold constants.
-
David Chatting - github.com/davidchatting/Approximate
MIT License - Copyright (c) February 2021, Updated 2026
*/

#include <Approximate.h>
Approximate approx;

void onProximateDevice(Device *device, Approximate::DeviceEvent event);
const char* getProximityZone(int rssi);

void setup() {
Serial.begin(9600);

if (approx.init("MyHomeWiFi", "password", false)) {
// Use PUBLIC threshold to detect at maximum range
Approximate::setProximateRSSIThreshold(APPROXIMATE_PUBLIC_RSSI);
// Devices depart after 5 seconds without a packet
Approximate::setProximateLastSeenTimeoutMs(5000);

approx.setProximateDeviceHandler(onProximateDevice);
approx.begin();
}
}

void loop() {
approx.loop();
}

void onProximateDevice(Device *device, Approximate::DeviceEvent event) {
int rssi = device->getRSSI();

switch (event) {
case Approximate::ARRIVE:
Serial.printf("ARRIVE\t%s\t[%s]\tRSSI: %i\n",
device->getMacAddressAsString().c_str(),
getProximityZone(rssi),
rssi);
break;
case Approximate::DEPART:
Serial.printf("DEPART\t%s\n",
device->getMacAddressAsString().c_str());
break;
case Approximate::PROBE:
Serial.printf("PROBE\t%s\t[%s]\tRSSI: %i\n",
device->getMacAddressAsString().c_str(),
getProximityZone(rssi),
rssi);
break;
default:
break;
}
}

const char* getProximityZone(int rssi) {
if (rssi > APPROXIMATE_INTIMATE_RSSI) return "INTIMATE";
if (rssi > APPROXIMATE_PERSONAL_RSSI) return "PERSONAL";
if (rssi > APPROXIMATE_SOCIAL_RSSI) return "SOCIAL";
return "PUBLIC";
}
3 changes: 3 additions & 0 deletions examples/WatchDevice/WatchDevice.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Approximate approx;

long ledOnUntilMs = 0;

void onProximateDevice(Device *device, Approximate::DeviceEvent event);
void onActiveDevice(Device *device, Approximate::DeviceEvent event);

void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
Expand Down
7 changes: 7 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ String_to_eth_addr KEYWORD2
eth_addr_to_String KEYWORD2
eth_addr_to_c_str KEYWORD2
wifi_csi_info_to_Channel KEYWORD2
getCountryCode KEYWORD2
getCountryEnvironment KEYWORD2
hasCountryInfo KEYWORD2
Packet_to_Device KEYWORD2

# methods from Device.h
Expand All @@ -66,6 +69,9 @@ getIPAddressAs_c_str KEYWORD2
setIPAddress KEYWORD2
hasIPAddress KEYWORD2

getSSIDAsString KEYWORD2
hasSSID KEYWORD2

setRSSI KEYWORD2
getRSSI KEYWORD2

Expand Down Expand Up @@ -113,6 +119,7 @@ DEPART LITERAL1
SEND LITERAL1
RECEIVE LITERAL1
INACTIVE LITERAL1
PROBE LITERAL1

# public constants from Device.h
APPROXIMATE_UNKNOWN_RSSI LITERAL1
Loading
Loading