IoT - Modular - WiFi.cpp
Jump to navigation
Jump to search
Contents
#includes, Defines, etc...
1 #include "libraries.h"
2 #include "functions.h"
3
4 ////////////////////////////////////////////////////////////////
5 // These exist because the variables are declared elsewhere in
6 // the project. (Specifically, in TopSecret.h)
7 extern char *WiFi_ssid;
8 extern char *WiFi_password;
9 extern char *WiFi_ClientName;
10 ////////////////////////////////////////////////////////////////
WiFi_init()
1 // Initialize the WiFi
2 //
3 // If we don't get a connection, we just keep trying forever.
4 // Probably be an idea to eventually just give up, but most
5 // ESP8266 devices are kinda useless without the connection...
6 void WiFi_init()
7 {
8 char debugTEXT[46];
9
10 WiFi.mode(WIFI_STA); // Connecting as a STATION
11 WiFi.begin(WiFi_ssid, WiFi_password);
12
13 // We start by connecting to a WiFi network
14 sprintf(debugTEXT, "Connecting to: %-22s", WiFi_ssid);
15 debug_SectionTitle(debugTEXT);
16 {
17 debug_ProgressBar0();
18 int dotcount = 0;
19 while (WiFi.status() != WL_CONNECTED) // Give it a bit of time to establish the WiFi connection...
20 {
21 dotcount++;
22 delay(500);
23 debug_ProgressBar1();
24 if (dotcount >= 46)
25 {
26 debug_ProgressBar2(dotcount);
27 dotcount = 0;
28 debug_ProgressBar0();
29 }
30 // SSD1306_Static(" no WiFi ", 3);
31 }
32 debug_ProgressBar2(dotcount);
33 }
34 sprintf(debugTEXT, "WiFi connected on Channel %-2d", WiFi.channel());
35 debug_LineOut(debugTEXT);
36 sprintf(debugTEXT, "IP address: %-15s", WiFi.localIP().toString().c_str());
37 debug_LineOut(debugTEXT);
38
39 sprintf(debugTEXT, "My name is NOT %-22s", wifi_station_get_hostname());
40 debug_LineOut(debugTEXT);
41 sprintf(debugTEXT, "Really... It's %-22s", WiFi_ClientName);
42 debug_LineOut(debugTEXT);
43
44 // SSD1306_Static(" WiFi good ", 3);
45
46 // Add "build_flags = -D DEBUG1" to your platformio.ini to get some extra WiFi stats
47 #ifdef DEBUG1
48 WiFi.printDiag(Serial);
49 sprintf(debugTEXT, "RSSI: %d dBm", WiFi.RSSI());
50 debug_LineOut(debugTEXT);
51 sprintf(debugTEXT, "HostName: %-13s !!!! BULLSHIT !!!!", WiFi.hostname().c_str());
52 debug_LineOut(debugTEXT);
53 // Apparently, the ESP8266WiFi library does not actually support DHCP completely
54 // { https://www.reddit.com/r/arduino/comments/d6mvc7/getting_hostname_from_dhcp_with_esp8266/ }
55 // { https://github.com/esp8266/Arduino/issues/5695 }
56 #endif
57 }
WiFi_strength()
1 int WiFi_strength()
2 {
3 return (WiFi.RSSI());
4 }
WiFi_Test()
1 int blip[3] = {000, 255, 000}; // GRN
2
3 void WiFi_Test() // Is Good... Maybe
4 {
5 if (WiFi.status() != WL_CONNECTED)
6 {
7 Serial.println("Oh Poop!");
8 blip[0] = 128;
9 blip[1] = 128;
10 }
11 else
12 {
13 if (blip[1] == 255)
14 blip[1] = 0;
15 else
16 blip[1] = 255;
17 }
18 #ifdef d_Pixels
19 SetAPixel(3, blip);
20 #endif // d_Pixels
21 }
WiFi_Test2()
1 int blip2[3] = {255, 000, 000}; // RED
2
3 void WiFi_Test2() // Lost WiFi
4 {
5 if (blip2[0] == 255)
6 blip2[0] = 0;
7 else
8 blip2[0] = 255;
9 #ifdef d_Pixels
10 SetAPixel(3, blip2);
11 #endif // d_Pixels
12 }
WiFi_Test3()
1 int blip3[3] = {255, 128, 000}; // ORA
2
3 void WiFi_Test3() // lost MQTT
4 {
5 if (blip3[0] == 255)
6 {
7 blip3[0] = 0;
8 blip3[1] = 0;
9 blip3[2] = 0;
10 }
11 else
12 {
13 blip3[0] = 255;
14 blip3[1] = 128;
15 blip3[2] = 000;
16 }
17 #ifdef d_Pixels
18 SetAPixel(3, blip3);
19 #endif // d_Pixels
20 }