Loom 4 v4.5
Arduino library for Internet of Things Rapid Prototyping in environmental sensing
Loading...
Searching...
No Matches
Loom_Wifi.h
1#pragma once
2
3#include <WiFi101.h>
4#include <WiFiUdp.h>
5#include <FlashStorage.h>
6
7
8#include "Module.h"
9#include "Loom_Manager.h"
10#include "../../../Hardware/Loom_BatchSD/Loom_BatchSD.h"
11
15enum CommunicationMode{
16 CLIENT, // Connect to a remote router to handle traffic
17 AP // Set the feather itself as an access point
18};
19
20/* WiFi info struct that will be used to store the WiFi data on flash */
21typedef struct {
22 bool is_valid;
23 char name[100];
24 char password[100];
25} WifiInfo;
26
32class Loom_WIFI : public Module{
33 protected:
34
35 /* These aren't used with the Wifi manager */
36 void measure() override {};
37
38 // Initialize the device and connect to the network
39 void initialize() override;
40 void package() override;
41
42 // Reconnect to the network
43 void power_up() override;
44
45 // Disconnect from the network
46 void power_down() override;
47
48 public:
49
57 Loom_WIFI(Manager& man, CommunicationMode mode, const char* name = "", const char* password = "", int connectionRetries = 5);
58
64 Loom_WIFI(Manager& man);
65
73 void loadConfigFromJSON(char* json);
74
79 WiFiClient& getClient() { return wifiClient; };
80
84 WiFiUDP* getUDP() { return new WiFiUDP(); };
85
89 bool verifyConnection();
90
94 void connect_to_network();
95
99 void start_ap();
100
101 /* Take in new WiFi information store it to flash and restart the WiFi chip to put the new credentials into effect*/
102 void storeNewWiFiCreds(const char* name, const char* password);
103
107 IPAddress getIPAddress();
108
112 IPAddress getSubnetMask();
113
117 IPAddress getGateway();
118
122 IPAddress getBroadcast();
123
124
128 bool isConnected();
129
133 void useMax() {usingMax = true; };
134
138 void setBatchSD(Loom_BatchSD& batch) { batchSD = &batch; };
139
143 void setMaxRetries(int retries) { connectionRetries = retries; };
144
148 void ipToString(IPAddress ip, char array[16]) {
149 snprintf(array, 16, "%u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]);
150 };
151
152 private:
153 Manager* manInst; // Pointer to the manager
154
155 WiFiClient wifiClient; // Wifi client that can be used with the MQTT client or other additional objects
156 Loom_BatchSD* batchSD = nullptr;
157
158 bool powerUp = true; // Whether or not the WiFi should power up (used with batch uploads)
159
160 char wifi_name[100]; // Access point to connect to
161 char wifi_password[100]; // Password to connect to the access point
162 int connectionRetries;
163
164 bool usingMax = false; // If we are using max
165 bool firstInit = true;
166 CommunicationMode mode; // Current WiFi mode we are in
167
168 IPAddress remoteIP; // IP address to send the UDP requests to
169
170
171};
Definition: Loom_BatchSD.h:9
Definition: Loom_Wifi.h:32
WiFiClient & getClient()
Definition: Loom_Wifi.h:79
void ipToString(IPAddress ip, char array[16])
Definition: Loom_Wifi.h:148
IPAddress getBroadcast()
Definition: Loom_Wifi.cpp:360
WiFiUDP * getUDP()
Definition: Loom_Wifi.h:84
void setBatchSD(Loom_BatchSD &batch)
Definition: Loom_Wifi.h:138
void loadConfigFromJSON(char *json)
Definition: Loom_Wifi.cpp:291
void start_ap()
Definition: Loom_Wifi.cpp:204
IPAddress getIPAddress()
Definition: Loom_Wifi.cpp:339
IPAddress getGateway()
Definition: Loom_Wifi.cpp:353
void connect_to_network()
Definition: Loom_Wifi.cpp:137
bool verifyConnection()
Definition: Loom_Wifi.cpp:250
bool isConnected()
Definition: Loom_Wifi.cpp:241
IPAddress getSubnetMask()
Definition: Loom_Wifi.cpp:346
void setMaxRetries(int retries)
Definition: Loom_Wifi.h:143
void useMax()
Definition: Loom_Wifi.h:133
Definition: Loom_Manager.h:18
Definition: Module.h:30
Definition: Loom_Wifi.h:21