-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLXDMXWiFiConfig.h
196 lines (165 loc) · 5.54 KB
/
LXDMXWiFiConfig.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**************************************************************************/
/*!
@file LXDMXWiFiconfig.h
@author Claude Heintz
@license BSD (see LXDMXWiFi.h or http://lx.claudeheintzdesign.com/opensource.html)
@copyright 2016-2018 by Claude Heintz All Rights Reserved
*/
/**************************************************************************/
#include <inttypes.h>
#include <string.h>
/*
structure for storing WiFi and Protocol configuration settings
*/
typedef struct dmxwifiConfig {
char ident[8]; // ESP-DMX\0
uint8_t opcode; // data = 0, query = '?', set ='!'
uint8_t version; // currently 1
uint8_t wifi_mode;
uint8_t protocol_flags;
char ssid[64]; // max is actually 32
char pwd[64]; // depends on security 8, 13, 8-63
uint32_t ap_address; // static IP address of access point
uint32_t ap_gateway; // gateway in access point mode
uint32_t ap_subnet; // subnet in access point mode
uint32_t sta_address; // static IP address in station mode (! DHCP bit set)
uint32_t sta_gateway; // gateway in station mode
uint32_t sta_subnet; // subnet in station mode
uint32_t multi_address; // multicast address for sACN
uint8_t sacn_universe; // should match multicast address
uint8_t artnet_portaddr_hi;
uint8_t artnet_portaddr_lo;
uint8_t sacn_universe_hi; // backwards compatability
char node_name[32];
uint32_t input_address; // IP address for sending DMX to network in input mode
uint16_t device_address; // dmx address (if applicable)
uint8_t reserved[22];
} DMXWiFiconfig;
#define CONFIG_PACKET_IDENT "ESP-DMX"
#define DMXWiFiConfigSIZE 232
#define DMXWiFiConfigMinSIZE 171
#define DMXWIFI_CONFIG_VERSION 1
#define DMXWIFI_CONFIG_INVALID_VERSION 27
#define STATION_MODE 0
#define AP_MODE 1
#define ARTNET_MODE 0
#define SACN_MODE 1
#define STATIC_MODE 2
#define MULTICAST_MODE 4
#define INPUT_TO_NETWORK_MODE 8
#define RDM_MODE 16
#define OUTPUT_FROM_NETWORK_MODE 0
/*!
@class DMXwifiConfig
@abstract
DMXwifiConfig abstracts WiFi and Protocol configuration settings so that they can
be saved and retrieved from persistent storage.
@discussion
To allow use of the configuration utility use DMXwifiConfig.begin(1);
When using remote configuration:
The remote configuration utility can be used to edit the settings without re-loading the sketch.
Settings from persistent memory.
Calling DMXwifiConfig.begin(0) temporarily uses the settings in the LXDMXWiFiConfig.initConfig() method.
This insures there is a default way of connecting to the sketch in order to use the remote utility,
even if it is configured to use a WiFi network that is unavailable.
Without remote configuration, ( using DMXwifiConfig.begin() or DMXwifiConfig.begin(0) ),
settings are read from the LXDMXWiFiConfig.initConfig() method.
In this case, it is necessary to edit that function and recompile the sketch in order to change the settings.
*/
class DMXwifiConfig {
public:
DMXwifiConfig ( void );
~DMXwifiConfig( void );
/*
handles init of config data structure, reading from persistent if desired.
returns 1 if boot uses default settings, 0 if settings are read from EEPROM
*/
uint8_t begin ( uint8_t mode = 0 );
/*
initConfig initializes the DMXWiFiConfig structure with default settings
The default is to receive Art-Net with the WiFi configured as an access point.
(Modify the initConfig to change default settings. But, highly recommend leaving AP_MODE for default startup.)
*/
void initConfig(void);
void initStandardConfig(void);
/*
WiFi setup parameters
*/
char* SSID(void);
char* password(void);
bool APMode(void);
bool staticIPAddress(void);
void setStaticIPAddress(uint8_t staticip);
void setSSID(char* s, uint8_t len);
void setPassword(char* s, uint8_t len);
void setStationMode(void);
/*
protocol modes
*/
bool artnetMode(void);
bool sACNMode(void);
bool multicastMode(void);
bool rdmMode(void);
bool inputToNetworkMode(void);
/*
stored IPAddresses
*/
IPAddress apIPAddress(void);
IPAddress apGateway(void);
IPAddress apSubnet(void);
IPAddress stationIPAddress(void);
void setStationIPAddress ( IPAddress addr );
IPAddress stationGateway(void);
IPAddress stationSubnet(void);
void setStationSubnetMask ( IPAddress submask );
IPAddress multicastAddress(void);
IPAddress inputAddress(void);
/*
dmx address
*/
uint16_t deviceAddress(void);
/*
protocol settings
*/
uint16_t sACNUniverse(void);
uint16_t artnetPortAddress(void);
void setArtNetPortAddress(uint16_t u);
char* nodeName(void);
void setNodeName(char* nn);
/*
copyConfig from uint8_t array
*/
void copyConfig(uint8_t* pkt, uint8_t size);
/*
read from EEPROM or flash
*/
uint8_t readFromPersistentStore(void);
/*
write to EEPROM or flash
*/
uint8_t commitToPersistentStore(void);
/*
pointer and size for UDP.write()
*/
uint8_t* config(void);
uint8_t configSize(void);
/*
Utility function. WiFi station password should never be returned by query.
*/
void hidePassword(void);
void restorePassword(void);
private:
/*
pointer to configuration structure
*/
DMXWiFiconfig* _wifi_config;
/*
saved password (never sent out in reply)
*/
char _save_pwd[64];
/*
nvs handle
*/
uint32_t _handle;
};
extern DMXwifiConfig DMXWiFiConfig;