@@ -0,0 +1,216 @@ | |||
// Arduino -> Adafruit ESP32 Feather auswählen | |||
#include <WiFi.h> | |||
#include <WiFiUDP.h> | |||
#include <stdio.h> | |||
#include <ctype.h> | |||
/* Martin Wimmer Hardwaretest 17.04.2019 | |||
* Firmware v1.1 04.04.2019 | |||
* Christian Schuster | |||
* cchschuster@gmail.com | |||
*/ | |||
#define SSID "featherNetwork" // network SSID | |||
#define PASSWORD "featherNetwork" // network password | |||
#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 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("Setting up AP at SSID: "); | |||
Serial.print(SSID); | |||
bool result = WiFi.softAP(SSID, PASSWORD); | |||
//result = false; // for error testing | |||
if(result) | |||
{ | |||
Serial.println(); | |||
Serial.println("...AP successfully built."); | |||
Serial.print("...Feather IP: "); | |||
Serial.println(WiFi.softAPIP()); | |||
Serial.print("...Feather MAC: "); | |||
Serial.println(WiFi.softAPmacAddress()); | |||
Serial.print("...Local port: "); | |||
Serial.println(localPort); | |||
successWiFi(); | |||
Serial.println("Listening to port..."); | |||
} else { | |||
Serial.println("...Failed while setting up access point"); | |||
errorWiFi(); | |||
} | |||
udp.begin(localPort); | |||
} | |||
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); | |||
} | |||
} | |||
} | |||
*/ | |||
// Test alle Kanäle | |||
allHigh(); | |||
delay(1000); | |||
allLow(); | |||
delay(1000); | |||
/* | |||
// Test Kanal L,R,V,Z | |||
for(char i='1' ; i<='4' ; i++) | |||
{ | |||
vibrate(i); | |||
delay(1000); | |||
vibrate('0'); | |||
delay(1000); | |||
} | |||
*/ | |||
} | |||
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() | |||
{ | |||
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() | |||
{ | |||
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; | |||
} | |||
} | |||
void allHigh() | |||
{ | |||
// Set all High | |||
digitalWrite(PIN_LED, HIGH); | |||
digitalWrite(PIN_Z, HIGH); | |||
digitalWrite(PIN_V, HIGH); | |||
digitalWrite(PIN_R, HIGH); | |||
digitalWrite(PIN_L, HIGH); | |||
// Bisher ungenutzte Pins | |||
digitalWrite(PIN_27, HIGH); | |||
digitalWrite(PIN_12, HIGH); | |||
digitalWrite(PIN_13, HIGH); | |||
digitalWrite(PIN_A5, HIGH); | |||
digitalWrite(PIN_A1, HIGH); | |||
digitalWrite(PIN_A0, HIGH); | |||
} |
@@ -0,0 +1,176 @@ | |||
// 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 | |||
*/ | |||
#define SSID "featherNetwork" // network SSID | |||
#define PASSWORD "featherNetwork" // network password | |||
#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 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("Setting up AP at SSID: "); | |||
Serial.print(SSID); | |||
bool result = WiFi.softAP(SSID, PASSWORD); | |||
//result = false; // for error testing | |||
if(result) | |||
{ | |||
Serial.println(); | |||
Serial.println("...AP successfully built."); | |||
Serial.print("...Feather IP: "); | |||
Serial.println(WiFi.softAPIP()); | |||
Serial.print("...Feather MAC: "); | |||
Serial.println(WiFi.softAPmacAddress()); | |||
Serial.print("...Local port: "); | |||
Serial.println(localPort); | |||
successWiFi(); | |||
Serial.println("Listening to port..."); | |||
} else { | |||
Serial.println("...Failed while setting up access point"); | |||
errorWiFi(); | |||
} | |||
udp.begin(localPort); | |||
} | |||
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() | |||
{ | |||
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() | |||
{ | |||
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; | |||
} | |||
} |
@@ -0,0 +1,240 @@ | |||
// 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[] = "Moto G (5S) 7000"; // network SSID (name) Mobile Hotspot | |||
// char ssid[] = "homenet27 Gast"; // network SSID (name) Wolfgang | |||
char ssid[] = "WLAN-79C670"; // network SSID (name) Igor | |||
// char pass[] = "8fb165b9c4b7"; // network password Mobile Hotspot | |||
// char pass[] = "0911533136"; // network password Wolfgang | |||
char pass[] = "9718701064420292"; // network password Igor | |||
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; | |||
} | |||
} |
@@ -0,0 +1,48 @@ | |||
/* | |||
* This sketch demonstrates how to scan WiFi networks. | |||
* The API is almost the same as with the WiFi Shield library, | |||
* the most obvious difference being the different file you need to include: | |||
*/ | |||
#include "WiFi.h" | |||
void setup() | |||
{ | |||
Serial.begin(115200); | |||
// Set WiFi to station mode and disconnect from an AP if it was previously connected | |||
WiFi.mode(WIFI_STA); | |||
WiFi.disconnect(); | |||
delay(100); | |||
Serial.println("Setup done"); | |||
} | |||
void loop() | |||
{ | |||
Serial.println("scan start"); | |||
// WiFi.scanNetworks will return the number of networks found | |||
int n = WiFi.scanNetworks(); | |||
Serial.println("scan done"); | |||
if (n == 0) { | |||
Serial.println("no networks found"); | |||
} else { | |||
Serial.print(n); | |||
Serial.println(" networks found"); | |||
for (int i = 0; i < n; ++i) { | |||
// Print SSID and RSSI for each network found | |||
Serial.print(i + 1); | |||
Serial.print(": "); | |||
Serial.print(WiFi.SSID(i)); | |||
Serial.print(" ("); | |||
Serial.print(WiFi.RSSI(i)); | |||
Serial.print(")"); | |||
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN)?" ":"*"); | |||
delay(10); | |||
} | |||
} | |||
Serial.println(""); | |||
// Wait a bit before scanning again | |||
delay(5000); | |||
} |