/* * 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 #include "ESP8266WiFi.h" #include "relais.h" #include "wlan.h" #include "fader.h" #include "ws2801.h" #include "ws2801_udp.h" #define NWLANFAV 5 const char *favorite_wlans[2*NWLANFAV] = { // SSID, password (NULL if unencrypted) "Error-404", "XKZbEF0AiMNPAGf4EbHAAZ", "Error-403", "2b4EWWpqAyCpgOQK1oeD", "bytewerk", "bluemchenwiese", "Freifunk", NULL, "franken.freifunk.net", NULL }; uint32_t fader_next_update = 0; uint32_t fader_loop = 0; void setup_wifi() { bool connected = false; for(int i = 0; i < NWLANFAV; i++) { connected = (0 == wlan_connectto(favorite_wlans[2*i + 0], favorite_wlans[2*i + 1])); if(connected) { break; } } if(!connected) { Serial.println("All predefined WLANs failed to connect. Trying any open network."); connected = (0 == wlan_connect_any_open()); } if(connected) { wlan_print_conninfo(); } else { Serial.println("All WLAN connections failed. Giving up for now."); } } void setup() { Serial.begin(115200); setup_wifi(); relais_setup(); ws2801_init(); fader_init(); ws2801_udp_setup(); for(int i = 0; i < MAX_NUM_MODULES; i++) { fader_set_colour(i, 0, 0, 0); fader_fade_colour(i, 0, 255, 0); } Serial.println("Setup done"); } void loop() { char buf[512]; if(WiFi.status() != WL_CONNECTED) { // wifi disconnected -> attempt reconnect delay(5000); setup_wifi(); } uint32_t now = millis(); if(now > fader_next_update) { fader_update(); fader_next_update += 10; // -> 100 FPS /* if((fader_loop % 200) == 0) { int round = (fader_loop / 200) % 3; if(round == 0) { for(int i = 0; i < MAX_NUM_MODULES; i++) { fader_fade_colour(i, 255, 0, 0); } } else if(round == 1) { for(int i = 0; i < MAX_NUM_MODULES; i++) { fader_fade_colour(i, 0, 255, 0); } } else { for(int i = 0; i < MAX_NUM_MODULES; i++) { fader_fade_colour(i, 0, 0, 255); } } } */ fader_loop++; } if(ws2801_udp_loop()) { relais_heartbeat(); } relais_loop(); }