dlareau / dailywalkbot

A twitter bot that will go on a random walk each day using google maps API. (a fun side project)
1 stars 1 forks source link

Is it possible to define area for walk? #3

Closed happytm closed 5 years ago

dlareau commented 5 years ago

In what way? Per instruction? Per day? In general?

It wouldn't be too hard to add a check on the new coordinate function to make sure the resulting coordinates to walk to fit some criteria (inside some defined area).

happytm commented 5 years ago

Sorry. I meant geographic area on map.

Thanks.

happytm commented 5 years ago

I see you have modified esp8266 sniffer code for custom use.I was going to comment in that repo but could not find issue tracker there so sorry for commenting here. I was trying to figure out what use you have for esp8266 sniffer after changes you made to code but I could not figure it out. can you please disclose how you are using it?

Thanks.

dlareau commented 5 years ago

Re: dailywalkbot: Yes, it is possible and not too hard to add a geographic area to stay inside so long as it is relatively easy to define that area. All that would really be needed is some "approval" function where the function gets passed a pair of coordinates and returns true if those coordinates are inside the area. So simple shapes would be super easy, but something like the boundary of a state or country could get harder

Re: esp8266 sniffer, if I remember correctly the modifications were a mix of code cleanup and some minor changes to allow me to more easily gather data about AP's clients, and who was talking to who.

happytm commented 5 years ago

Thank you for your prompt reply. I will try to set coordinates filter. For sniffer code I am going to use it to get data from battery powered sensors (like esp-now).The idea is to create fake MAC id on remote sensor with small data loaded in it. It will be limited data but couple of bytes of data will be all I need.

Thanks

dlareau commented 5 years ago

dailywalkbot: Yeah, you just want to add some code near line 135 of dailywalk.py that says something like

if(not checkInArea(new_lat, new_lng)):
    continue

and then define the function checkInArea(lat, long) to take a lat and long pair and return true or false for whether or not it is in the area you want.

esp8266: I wish you well on your project, but I do not think my modifications will be helpful for your needs and can't offer any specific advice on the matter.

happytm commented 5 years ago

Thanks for hint regarding dailywalkbot.

Regarding your sniffer code I was able to cobble together a working solution for my needs. following are sender and receiver code which does the job:

Sender Code:

` /*

extern "C" void preinit() {

// Change MAC

//uint8_t mac[] = { 0xb4, 0xe6, 0x52, 0x44, 0x86, 0xad }; uint8_t mac[6]; mac[0] = temperature; mac[1] = humidity; mac[2] = pressure; mac[3] = pressure; mac[4] = random(256); mac[5] = random(256);

wifi_set_opmode (STATION_MODE); wifi_set_macaddr(STATION_IF, mac); }

extern "C" {

include

}

// this is the MAC Address of the remote ESP server which receives these sensor readings uint8_t remoteMac[] = {0x36, 0x33, 0x33, 0x33, 0x33, 0x33};

define WIFI_CHANNEL 1

//#define SLEEP_SECS 15 * 60 // 15 minutes

define SLEEP_SECS 5000

define SEND_TIMEOUT 245 // 245 millis seconds timeout

define MESSAGELEN 10

unsigned long entry;

// keep in sync with slave struct struct attribute((packed)) SENSOR_DATA { // float temp; // float humidity; // float pressure; char testdata[MESSAGELEN]; } sensorData;

volatile boolean callbackCalled;

unsigned long entry1 = millis();

void prinScanResult(int networksFound) { Serial.printf("%d network(s) found\n", networksFound); for (int i = 0; i < networksFound; i++) { Serial.printf("%d: %s, Ch:%d (%ddBm) %s\n", i + 1, WiFi.SSID(i).c_str(), WiFi.channel(i), WiFi.RSSI(i), WiFi.encryptionType(i) == ENC_TYPE_NONE ? "open" : ""); } }

void setup() { int i = 0; Serial.begin(115200); Serial.println(); Serial.println("ESP_Now SENDER");

// WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(10); WiFi.scanNetworksAsync(prinScanResult);

WiFi.hostname("Livingroom"); Serial.println(WiFi.macAddress()); Serial.printf("target mac: %02x%02x%02x%02x%02x%02x", remoteMac[0], remoteMac[1], remoteMac[2], remoteMac[3], remoteMac[4], remoteMac[5]); Serial.printf(", channel: %i\n", WIFI_CHANNEL);

if (esp_now_init() != 0) { Serial.println("*** ESP_Now init failed"); //gotoSleep(); } esp_now_set_self_role(ESP_NOW_ROLE_CONTROLLER); Serial.println(millis() - entry1); unsigned long entry2 = millis(); esp_now_add_peer(remoteMac, ESP_NOW_ROLE_SLAVE, WIFI_CHANNEL, NULL, 0); Serial.println(millis() - entry2); unsigned long entry3 = millis();

esp_now_register_send_cb([](uint8_t* mac, uint8_t sendStatus) { Serial.printf("send_cb, send done, status = %i\n", sendStatus); callbackCalled = true; }); Serial.println(millis() - entry3); unsigned long entry4 = millis();

callbackCalled = false;

for (i = 0; i < MESSAGELEN; i++) sensorData.testdata[i] = '0'; sensorData.testdata[MESSAGELEN] = '\0';

}

void loop() {

WiFi.scanNetworksAsync(prinScanResult); Serial.println(WiFi.macAddress()); Serial.println(WiFi.hostname()); delay(10); uint8_t bs[sizeof(sensorData)]; memcpy(bs, &sensorData, sizeof(sensorData)); unsigned long entry = millis(); esp_now_send(NULL, bs, sizeof(sensorData)); // NULL means send to all peers Serial.print("Time to send: "); Serial.println(millis() - entry); Serial.print("Overall Time: "); Serial.println(millis() - entry1); Serial.print("Size: "); Serial.println(sizeof(bs)); //ESP.deepSleep(0); delay(10000);

}

void gotoSleep() { //need connection between GPIO16 and reset pin on ESP8266 // add some randomness to avoid collisions with multiple devices int sleepSecs = SLEEP_SECS;// + ((uint8_t)RANDOM_REG32/2); Serial.printf("Up for %i ms, going to sleep for %i secs...\n", millis(), sleepSecs); ESP.deepSleep(sleepSecs * 1000000, RF_NO_CAL); }`

Receiver Code:

`/ Copyright 2017 Andreas Spiess Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. This software is based on the work of Ray Burnette: https://www.hackster.io/rayburne/esp8266-mini-sniff-f6b93a /

include

include

// #include

include

include

include "./functions.h"

include "./mqtt.h"

define disable 0

define enable 1

define SENDTIME 30000

define MAXDEVICES 60

define JBUFFER 15+ (MAXDEVICES * 40)

define PURGETIME 600000

define MINRSSI -70

// uint8_t channel = 1; unsigned int channel = 1; int clients_known_count_old, aps_known_count_old; unsigned long sendEntry, deleteEntry; char jsonString[JBUFFER];

String device[MAXDEVICES]; int nbrDevices = 0; int usedChannels[15];

ifndef CREDENTIALS

define mySSID "myssid"

define myPASSWORD "mypassword"

endif

StaticJsonBuffer jsonBuffer;

void setup() { Serial.begin(115200); Serial.printf("\n\nSDK version:%s\n\r", system_get_sdk_version()); Serial.println(F("Human detector by Andreas Spiess. ESP8266 mini-sniff by Ray Burnette http://www.hackster.io/rayburne/projects")); Serial.println(F("Based on the work of Ray Burnette http://www.hackster.io/rayburne/projects"));

wifi_set_opmode(STATION_MODE); // Promiscuous works only with station mode wifi_set_channel(channel); wifi_promiscuous_enable(disable); wifi_set_promiscuous_rx_cb(promisc_cb); // Set up promiscuous callback wifi_promiscuous_enable(enable); }

void loop() { channel = 1; boolean sendMQTT = false; wifi_set_channel(channel); while (true) { nothing_new++; // Array is not finite, check bounds and adjust if required if (nothing_new > 200) { // monitor channel for 200 ms nothing_new = 0; channel++; if (channel == 15) break; // Only scan channels 1 to 14 wifi_set_channel(channel); } delay(1); // critical processing timeslice for NONOS SDK! No delay(0) yield()

if (clients_known_count > clients_known_count_old) {
  clients_known_count_old = clients_known_count;
  sendMQTT = true;
}
if (aps_known_count > aps_known_count_old) {
  aps_known_count_old = aps_known_count;
  sendMQTT = true;
}
if (millis() - sendEntry > SENDTIME) {
  sendEntry = millis();
  sendMQTT = true;
}

} purgeDevice(); if (sendMQTT) { showDevices(); sendDevices(); } }

void connectToWiFi() { delay(10); // We start by connecting to a WiFi network Serial.println(); Serial.print("Connecting to "); Serial.println(mySSID);

WiFi.mode(WIFI_STA); WiFi.begin(mySSID, myPASSWORD);

while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }

Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); }

void purgeDevice() { for (int u = 0; u < clients_known_count; u++) { if ((millis() - clients_known[u].lastDiscoveredTime) > PURGETIME) { Serial.print("purge Client" ); Serial.println(u); for (int i = u; i < clients_known_count; i++) memcpy(&clients_known[i], &clients_known[i + 1], sizeof(clients_known[i])); clients_known_count--; break; } } for (int u = 0; u < aps_known_count; u++) { if ((millis() - aps_known[u].lastDiscoveredTime) > PURGETIME) { Serial.print("purge Bacon" ); Serial.println(u); for (int i = u; i < aps_known_count; i++) memcpy(&aps_known[i], &aps_known[i + 1], sizeof(aps_known[i])); aps_known_count--; break; } } }

void showDevices() { Serial.println(""); Serial.println(""); Serial.println("-------------------Device DB-------------------"); Serial.printf("%4d Devices + Clients.\n",aps_known_count + clients_known_count); // show count

// show Beacons for (int u = 0; u < aps_known_count; u++) { Serial.printf( "%4d ",u); // Show beacon number Serial.print("B "); Serial.print(formatMac1(aps_known[u].bssid)); Serial.print(" RSSI "); Serial.print(aps_known[u].rssi); Serial.print(" channel "); Serial.println(aps_known[u].channel); }

// show Clients for (int u = 0; u < clients_known_count; u++) { Serial.printf("%4d ",u); // Show client number Serial.print("C "); Serial.print(formatMac1(clients_known[u].station)); Serial.print(" RSSI "); Serial.print(clients_known[u].rssi); Serial.print(" channel "); Serial.println(clients_known[u].channel); } }

void sendDevices() { String deviceMac;

// Setup MQTT wifi_promiscuous_enable(disable); connectToWiFi(); client.setServer(mqttServer, 1883); while (!client.connected()) { Serial.println("Connecting to MQTT...");

if (client.connect("ESP32Client", "admin", "admin" )) {
  Serial.println("connected");
} else {
  Serial.print("failed with state ");
  Serial.println(client.state());
}
yield();

}

// Purge json string jsonBuffer.clear(); JsonObject& root = jsonBuffer.createObject(); JsonArray& mac = root.createNestedArray("MAC"); // JsonArray& rssi = root.createNestedArray("RSSI");

// add Beacons for (int u = 0; u < aps_known_count; u++) { deviceMac = formatMac1(aps_known[u].bssid); if (aps_known[u].rssi > MINRSSI) { mac.add(deviceMac); // rssi.add(aps_known[u].rssi); } }

// Add Clients for (int u = 0; u < clients_known_count; u++) { deviceMac = formatMac1(clients_known[u].station); if (clients_known[u].rssi > MINRSSI) { mac.add(deviceMac); // rssi.add(clients_known[u].rssi); } }

Serial.println(); Serial.printf("number of devices: %02d\n", mac.size()); root.prettyPrintTo(Serial); root.printTo(jsonString); // Serial.println((jsonString)); // Serial.println(root.measureLength()); if (client.publish("Sniffer", jsonString) == 1) Serial.println("Successfully published"); else { Serial.println(); Serial.println("!!!!! Not published. Please add #define MQTT_MAX_PACKET_SIZE 2048 at the beginning of PubSubClient.h file"); Serial.println(); } client.loop(); client.disconnect (); delay(100); wifi_promiscuous_enable(enable); sendEntry = millis(); }`

Thanks

happytm commented 5 years ago

Now it will be nice to filter out all traffic except these esp8266 sensor devices somehow to get clean data from them. Please help me if you know how to filter unwanted traffic.

Thanks