#include "ESP8266lib/io/IO.h" #include "ESP8266lib/ext/led/WS2812B.h" const uint16_t localPort = 1337; //const char* remoteIP = "192.168.22.255"; // OGWLAN //const char* remoteIP = "192.168.24.255"; // UGWLAN const char* remoteIP = "255.255.255.255"; // BUZZER const uint16_t remotePort = 7331; //char ssid[32] = "OGWLAN"; //char password[64] = "LeckereKekse!"; //char ssid[32] = "UGWLAN"; //char password[64] = "LeckereKekse!"; char ssid[32] = "Buzzer"; char password[64] = "LeckereKekse!"; #include "ADC.h" #include "Buzzer.h" Buzzer buzzer; bool connected; void onWifiEvent(System_Event_t* evt) { os_printf("event %x\n", evt->event); switch (evt->event) { case EVENT_STAMODE_CONNECTED: os_printf("connect to ssid %s, channel %d\n", evt->event_info.connected.ssid, evt->event_info.connected.channel); buzzer.setRGB(0,0,255); // blue break; case EVENT_STAMODE_GOT_IP: os_printf("got IP\n"); buzzer.setOff(); connected = true; buzzer.sendHeartbeat(); break; case EVENT_STAMODE_DISCONNECTED: os_printf("disconnect from ssid %s, reason %d\n", evt->event_info.disconnected.ssid, evt->event_info.disconnected.reason); buzzer.setRGB(255,0,0); break; } } void my_init() { connected = false; wifi_station_disconnect(); os_delay_us(1000*250); os_printf("my_init\r\n"); // stty -F /dev/ttyUSB0 115200 raw -echo && cat /dev/ttyUSB0 // yellow buzzer.setRGB(255,255,0); // register the event handler wifi_set_event_handler_cb(onWifiEvent); // i am a client wifi_set_opmode(STATION_MODE); wifi_station_disconnect(); os_delay_us(1000*500); // connect struct station_config stationConf; os_memset(&stationConf, 0, sizeof(stationConf)); os_memcpy(&stationConf.ssid, ssid, 32); os_memcpy(&stationConf.password, password, 32); wifi_station_set_config(&stationConf); wifi_station_connect(); // power safe //NONE_SLEEP_T //LIGHT_SLEEP_T //MODEM_SLEEP_T //wifi_set_opmode_current(NULL_MODE); //wifi_set_sleep_type(LIGHT_SLEEP_T); //wifi_set_sleep_type(MODEM_SLEEP_T); // green buzzer.setRGB(0,255,0); os_delay_us(1000*150); } void my_once() { //buzzer.setFade(); //buzzer.setStrobo(255,255,255); } void my_loop() { // 1 ms delay os_delay_us(1000); if (connected) { buzzer.update(); } }