|
|
@@ -0,0 +1,246 @@ |
|
|
|
// 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 |
|
|
|
* Implement Autoconnect to Home Network |
|
|
|
* |
|
|
|
* Firmware v1.3 06.11.2020 |
|
|
|
* Igor Beloschapkin |
|
|
|
* beloschapkin@protonmail.com |
|
|
|
* Add Support for 6 Taktilos |
|
|
|
* |
|
|
|
*/ |
|
|
|
|
|
|
|
// define PINs |
|
|
|
#define PIN_LED 13 |
|
|
|
#define PIN_TAC6 12 |
|
|
|
#define PIN_TAC5 27 |
|
|
|
#define PIN_TAC4 14 |
|
|
|
#define PIN_TAC3 32 |
|
|
|
#define PIN_TAC2 15 |
|
|
|
#define PIN_TAC1 33 |
|
|
|
#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_TAC6, OUTPUT); |
|
|
|
pinMode(PIN_TAC5, OUTPUT); |
|
|
|
pinMode(PIN_TAC4, OUTPUT); |
|
|
|
pinMode(PIN_TAC3, OUTPUT); |
|
|
|
pinMode(PIN_TAC2, OUTPUT); |
|
|
|
pinMode(PIN_TAC1, OUTPUT); |
|
|
|
|
|
|
|
// Bisher ungenutzte Pins |
|
|
|
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_TAC6, LOW); |
|
|
|
digitalWrite(PIN_TAC5, LOW); |
|
|
|
digitalWrite(PIN_TAC4, LOW); |
|
|
|
digitalWrite(PIN_TAC3, LOW); |
|
|
|
digitalWrite(PIN_TAC2, LOW); |
|
|
|
digitalWrite(PIN_TAC1, LOW); |
|
|
|
|
|
|
|
// Bisher ungenutzte Pins |
|
|
|
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 '6': digitalWrite(PIN_TAC6, HIGH); break; |
|
|
|
case '5': digitalWrite(PIN_TAC5, HIGH); break; |
|
|
|
case '4': digitalWrite(PIN_TAC4, HIGH); break; |
|
|
|
case '3': digitalWrite(PIN_TAC3, HIGH); break; |
|
|
|
case '2': digitalWrite(PIN_TAC2, HIGH); break; |
|
|
|
case '1': digitalWrite(PIN_TAC1, HIGH); break; |
|
|
|
case '0': allLow(); break; |
|
|
|
} |
|
|
|
} |