|
|
|
|
|
|
|
|
// Arduino -> Adafruit ESP32 Feather auswählen |
|
|
|
|
|
|
|
|
|
|
|
#include <WiFi.h> |
|
|
|
|
|
#include <WiFiUDP.h> |
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
#include <ctype.h> |
|
|
|
|
|
|
|
|
|
|
|
/* Firmware v1.1 04.04.2019 |
|
|
|
|
|
* Christian Schuster |
|
|
|
|
|
* cchschuster@gmail.com |
|
|
|
|
|
* |
|
|
|
|
|
* Firmware v1.2 03.08.2020 |
|
|
|
|
|
* Igor Beloschapkin |
|
|
|
|
|
* beloschapkin@protonmail.com |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#define PIN_LED 13 |
|
|
|
|
|
#define PIN_Z 14 |
|
|
|
|
|
#define PIN_V 32 |
|
|
|
|
|
#define PIN_R 15 |
|
|
|
|
|
#define PIN_L 33 |
|
|
|
|
|
#define PIN_27 27 |
|
|
|
|
|
#define PIN_12 12 |
|
|
|
|
|
#define PIN_13 13 |
|
|
|
|
|
#define PIN_A5 4 |
|
|
|
|
|
#define PIN_A1 25 |
|
|
|
|
|
#define PIN_A0 26 |
|
|
|
|
|
|
|
|
|
|
|
#define SCRIPTMODE 1 // 0 = local filtering, 1 = laptop script filtering |
|
|
|
|
|
|
|
|
|
|
|
char ssid[] = "ssid"; |
|
|
|
|
|
char pass[] = "pass"; |
|
|
|
|
|
|
|
|
|
|
|
char packetBuffer[255]; // buffer to hold incoming packet |
|
|
|
|
|
unsigned int localPort = 8888; |
|
|
|
|
|
|
|
|
|
|
|
char sig_nr; |
|
|
|
|
|
int i_sig_nr; |
|
|
|
|
|
|
|
|
|
|
|
WiFiUDP udp; |
|
|
|
|
|
|
|
|
|
|
|
void setup() |
|
|
|
|
|
{ |
|
|
|
|
|
setInitGPIO(); |
|
|
|
|
|
|
|
|
|
|
|
// Initialize serial |
|
|
|
|
|
Serial.begin(115200); |
|
|
|
|
|
Serial.println(); |
|
|
|
|
|
Serial.print("Connecting to WIFI at SSID: "); |
|
|
|
|
|
Serial.print(ssid); |
|
|
|
|
|
|
|
|
|
|
|
// Connect to WPA/WPA2 network: |
|
|
|
|
|
bool result = WiFi.begin(ssid, pass); |
|
|
|
|
|
|
|
|
|
|
|
// Wait 10 seconds for connection: |
|
|
|
|
|
delay(10000); |
|
|
|
|
|
|
|
|
|
|
|
//result = false; // for error testing |
|
|
|
|
|
if(result) |
|
|
|
|
|
{ |
|
|
|
|
|
successWiFi(); |
|
|
|
|
|
udp.begin(localPort); |
|
|
|
|
|
} else { |
|
|
|
|
|
errorWiFi(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void printWifiData() { |
|
|
|
|
|
// print your WiFi shield's IP address: |
|
|
|
|
|
IPAddress ip = WiFi.localIP(); |
|
|
|
|
|
Serial.print("IP Address: "); |
|
|
|
|
|
Serial.println(ip); |
|
|
|
|
|
Serial.println(ip); |
|
|
|
|
|
|
|
|
|
|
|
// print your MAC address: |
|
|
|
|
|
byte mac[6]; |
|
|
|
|
|
WiFi.macAddress(mac); |
|
|
|
|
|
Serial.print("MAC address: "); |
|
|
|
|
|
Serial.print(mac[5], HEX); |
|
|
|
|
|
Serial.print(":"); |
|
|
|
|
|
Serial.print(mac[4], HEX); |
|
|
|
|
|
Serial.print(":"); |
|
|
|
|
|
Serial.print(mac[3], HEX); |
|
|
|
|
|
Serial.print(":"); |
|
|
|
|
|
Serial.print(mac[2], HEX); |
|
|
|
|
|
Serial.print(":"); |
|
|
|
|
|
Serial.print(mac[1], HEX); |
|
|
|
|
|
Serial.print(":"); |
|
|
|
|
|
Serial.println(mac[0], HEX); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void printCurrentNet() { |
|
|
|
|
|
// print the SSID of the network you're attached to: |
|
|
|
|
|
Serial.print("SSID: "); |
|
|
|
|
|
Serial.println(WiFi.SSID()); |
|
|
|
|
|
|
|
|
|
|
|
// print the MAC address of the router you're attached to: |
|
|
|
|
|
// byte bssid[6]; |
|
|
|
|
|
// WiFi.BSSID(bssid); |
|
|
|
|
|
// Serial.print("BSSID: "); |
|
|
|
|
|
// Serial.print(bssid[5], HEX); |
|
|
|
|
|
// Serial.print(":"); |
|
|
|
|
|
// Serial.print(bssid[4], HEX); |
|
|
|
|
|
// Serial.print(":"); |
|
|
|
|
|
// Serial.print(bssid[3], HEX); |
|
|
|
|
|
// Serial.print(":"); |
|
|
|
|
|
// Serial.print(bssid[2], HEX); |
|
|
|
|
|
// Serial.print(":"); |
|
|
|
|
|
// Serial.print(bssid[1], HEX); |
|
|
|
|
|
// Serial.print(":"); |
|
|
|
|
|
// Serial.println(bssid[0], HEX); |
|
|
|
|
|
|
|
|
|
|
|
// print the received signal strength: |
|
|
|
|
|
long rssi = WiFi.RSSI(); |
|
|
|
|
|
Serial.print("signal strength (RSSI):"); |
|
|
|
|
|
Serial.println(rssi); |
|
|
|
|
|
|
|
|
|
|
|
// print the encryption type: |
|
|
|
|
|
// byte encryption = WiFi.encryptionType(); |
|
|
|
|
|
// Serial.print("Encryption Type:"); |
|
|
|
|
|
// Serial.println(encryption, HEX); |
|
|
|
|
|
// Serial.println(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void loop() |
|
|
|
|
|
{ |
|
|
|
|
|
int packetSize = udp.parsePacket(); |
|
|
|
|
|
if(packetSize) |
|
|
|
|
|
{ |
|
|
|
|
|
int len = udp.read(packetBuffer, 255); |
|
|
|
|
|
if(len) |
|
|
|
|
|
{ |
|
|
|
|
|
packetBuffer[len] = 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(SCRIPTMODE) // == 1 |
|
|
|
|
|
{ |
|
|
|
|
|
// laptop script filtering |
|
|
|
|
|
sig_nr = packetBuffer[0]; |
|
|
|
|
|
Serial.println(sig_nr); |
|
|
|
|
|
vibrate(sig_nr); |
|
|
|
|
|
} else { |
|
|
|
|
|
// local filtering |
|
|
|
|
|
if(strstr(packetBuffer,"usCode ")) |
|
|
|
|
|
{ |
|
|
|
|
|
sig_nr = packetBuffer[13]; |
|
|
|
|
|
Serial.println(sig_nr); |
|
|
|
|
|
vibrate(sig_nr); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void setInitGPIO() |
|
|
|
|
|
{ |
|
|
|
|
|
// Set all as OUTPUT |
|
|
|
|
|
pinMode(PIN_LED, OUTPUT); |
|
|
|
|
|
pinMode(PIN_Z, OUTPUT); |
|
|
|
|
|
pinMode(PIN_V, OUTPUT); |
|
|
|
|
|
pinMode(PIN_R, OUTPUT); |
|
|
|
|
|
pinMode(PIN_L, OUTPUT); |
|
|
|
|
|
|
|
|
|
|
|
// Bisher ungenutzte Pins |
|
|
|
|
|
pinMode(PIN_27, OUTPUT); |
|
|
|
|
|
pinMode(PIN_12, OUTPUT); |
|
|
|
|
|
pinMode(PIN_13, OUTPUT); |
|
|
|
|
|
pinMode(PIN_A5, OUTPUT); |
|
|
|
|
|
pinMode(PIN_A1, OUTPUT); |
|
|
|
|
|
pinMode(PIN_A0, OUTPUT); |
|
|
|
|
|
|
|
|
|
|
|
allLow(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void allLow() |
|
|
|
|
|
{ |
|
|
|
|
|
// Set all LOW |
|
|
|
|
|
digitalWrite(PIN_LED, LOW); |
|
|
|
|
|
digitalWrite(PIN_Z, LOW); |
|
|
|
|
|
digitalWrite(PIN_V, LOW); |
|
|
|
|
|
digitalWrite(PIN_R, LOW); |
|
|
|
|
|
digitalWrite(PIN_L, LOW); |
|
|
|
|
|
|
|
|
|
|
|
// Bisher ungenutzte Pins |
|
|
|
|
|
digitalWrite(PIN_27, LOW); |
|
|
|
|
|
digitalWrite(PIN_12, LOW); |
|
|
|
|
|
digitalWrite(PIN_13, LOW); |
|
|
|
|
|
digitalWrite(PIN_A5, LOW); |
|
|
|
|
|
digitalWrite(PIN_A1, LOW); |
|
|
|
|
|
digitalWrite(PIN_A0, LOW); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void errorWiFi() |
|
|
|
|
|
{ |
|
|
|
|
|
Serial.println("...Failed while connecting to Network"); |
|
|
|
|
|
delay(2000); |
|
|
|
|
|
while(true) |
|
|
|
|
|
{ |
|
|
|
|
|
digitalWrite(PIN_LED, HIGH); |
|
|
|
|
|
delay(100); |
|
|
|
|
|
digitalWrite(PIN_LED, LOW); |
|
|
|
|
|
delay(100); |
|
|
|
|
|
digitalWrite(PIN_LED, HIGH); |
|
|
|
|
|
delay(100); |
|
|
|
|
|
digitalWrite(PIN_LED, LOW); |
|
|
|
|
|
delay(1000); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void successWiFi() |
|
|
|
|
|
{ |
|
|
|
|
|
Serial.print("You're connected to the network"); |
|
|
|
|
|
// Print out data |
|
|
|
|
|
printCurrentNet(); |
|
|
|
|
|
printWifiData(); |
|
|
|
|
|
delay(2000); |
|
|
|
|
|
for(int i = 0; i < 5; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
digitalWrite(PIN_LED, HIGH); |
|
|
|
|
|
delay(1000); |
|
|
|
|
|
digitalWrite(PIN_LED, LOW); |
|
|
|
|
|
delay(200); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void vibrate(const char signr) |
|
|
|
|
|
{ |
|
|
|
|
|
switch(signr) |
|
|
|
|
|
{ |
|
|
|
|
|
case '4': digitalWrite(PIN_Z, HIGH); break; |
|
|
|
|
|
case '3': digitalWrite(PIN_V, HIGH); break; |
|
|
|
|
|
case '2': digitalWrite(PIN_R, HIGH); break; |
|
|
|
|
|
case '1': digitalWrite(PIN_L, HIGH); break; |
|
|
|
|
|
case '0': allLow(); break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|