@@ -36,8 +36,20 @@ extern "C" {
36
36
37
37
using namespace Menu ;
38
38
39
- const char * ssid = " r-site.net" ;
40
- const char * password = " rsite.2011" ;
39
+ #define ANALOG_PIN 4
40
+
41
+ #ifndef MENU_SSID
42
+ #error "need to define WiFi SSID here"
43
+ #define MENU_SSID " r-site.net"
44
+ #endif
45
+ #ifndef MENU_PASS
46
+ #error "need to define WiFi password here"
47
+ #define MENU_PASS " "
48
+ #endif
49
+
50
+ const char * ssid = MENU_SSID;
51
+ const char * password = MENU_PASS;
52
+ const char * serverName=" 192.168.1.79" ;
41
53
#ifdef DEBUG
42
54
// on debug mode I put aux files on external server to allow changes without SPIFF update
43
55
// on this mode the browser MUST be instructed to accept cross domain files
@@ -76,8 +88,12 @@ result action2(eventMask event, navNode& nav, prompt &item) {
76
88
}
77
89
78
90
int ledCtrl=LOW;
91
+ #define LEDPIN LED_BUILTIN
92
+ void updLed () {
93
+ digitalWrite (LEDPIN,!ledCtrl);
94
+ }
79
95
80
- TOGGLE (ledCtrl,setLed," Led: " ,doNothing,noEvent ,noStyle// ,doExit,enterEvent,noStyle
96
+ TOGGLE (ledCtrl,setLed," Led: " ,updLed,enterEvent ,noStyle// ,doExit,enterEvent,noStyle
81
97
,VALUE(" On" ,HIGH,doNothing,noEvent)
82
98
,VALUE(" Off" ,LOW,doNothing,noEvent)
83
99
);
@@ -97,13 +113,17 @@ CHOOSE(chooseTest,chooseMenu,"Choose",doNothing,noEvent,noStyle
97
113
,VALUE(" Last" ,-1 ,doNothing,noEvent)
98
114
);
99
115
116
+ int timeOn=50 ;
117
+ void updAnalog () {
118
+ analogWrite (ANALOG_PIN,map (timeOn,0 ,100 ,0 ,PWMRANGE));
119
+ }
120
+
100
121
// the menu
101
- int timeOn;
102
122
MENU (mainMenu," Main menu" ,doNothing,noEvent,wrapStyle
103
123
,SUBMENU(setLed)
104
124
,OP(" Action A" ,action1,enterEvent)
105
125
,OP(" Action B" ,action2,enterEvent)
106
- ,FIELD(timeOn," On" ," ms" ,0 ,500 , 100 ,10 , doNothing, noEvent , noStyle)
126
+ ,FIELD(timeOn," On" ," ms" ,0 ,100 ,10 ,1 , updAnalog, anyEvent , noStyle)
107
127
,SUBMENU(selMenu)
108
128
,SUBMENU(chooseMenu)
109
129
);
@@ -124,37 +144,39 @@ NAVROOT(nav,mainMenu,MAX_DEPTH,serial,out);
124
144
void webSocketEvent (uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
125
145
switch (type) {
126
146
case WStype_DISCONNECTED:
127
- USE_SERIAL.printf (" [%u] Disconnected!\n " , num);
147
+ // USE_SERIAL.printf("[%u] Disconnected!\n", num);
128
148
break ;
129
149
case WStype_CONNECTED: {
130
150
IPAddress ip = webSocket.remoteIP (num);
131
- USE_SERIAL.printf (" [%u] Connected from %d.%d.%d.%d url: %s\n " , num, ip[0 ], ip[1 ], ip[2 ], ip[3 ], payload);
151
+ // USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
132
152
webSocket.sendTXT (num, " console.log('ArduinoMenu Connected')" );
133
153
}
134
154
break ;
135
155
case WStype_TEXT:
136
- USE_SERIAL.printf (" [%u] get Text: %s\n " , num, payload);
156
+ // USE_SERIAL.printf("[%u] get Text: %s\n", num, payload);
137
157
nav.async ((const char *)payload);// this is slow!!!!!!!!
138
158
break ;
139
159
case WStype_BIN: {
140
- USE_SERIAL.printf (" [WSc] get binary length: %u" , length);
141
- Serial<<endl;
142
- /* for(int c=0;c<length;c++)
143
- USE_SERIAL<<*(char*)(payload+c);*/
160
+ USE_SERIAL<<" [WSc] get binary length:" <<length<<" [" ;
161
+ for (int c=0 ;c<length;c++) {
162
+ USE_SERIAL.print (*(char *)(payload+c),HEX);
163
+ USE_SERIAL.write (' ,' );
164
+ }
165
+ Serial<<" ]" <<endl;
144
166
uint16_t id=*(uint16_t *) payload++;
145
167
idx_t len=*((idx_t *)++payload);
146
168
idx_t * pathBin=(idx_t *)++payload;
147
169
const char * inp=(const char *)(payload+len);
148
- Serial<<" id:" <<id<<endl;
170
+ // Serial<<"id:"<<id<<endl;
149
171
if (id==nav.active ().hash ()) {
150
- Serial<<" id ok." <<endl;Serial.flush ();
151
- Serial<<" input:" <<inp<<endl;
172
+ // Serial<<"id ok."<<endl;Serial.flush();
173
+ // Serial<<"input:"<<inp<<endl;
152
174
// StringStream inStr(inp);
153
175
// while(inStr.available())
154
176
nav.doInput (inp);
155
177
webSocket.sendTXT (num, " binBusy=false;" );// send javascript to unlock the state
156
- } else Serial<<" id not ok!" <<endl;
157
- Serial<<endl;
178
+ } // else Serial<<"id not ok!"<<endl;
179
+ // Serial<<endl;
158
180
}
159
181
break ;
160
182
}
@@ -164,12 +186,14 @@ void pageStart() {
164
186
server.sendHeader (" Cache-Control" ," no-cache, no-store, must-revalidate" );
165
187
server.sendHeader (" Pragma" ," no-cache" );
166
188
server.sendHeader (" Expires" ," 0" );
167
- serverOut<<
168
- " <?xml version=\" 1.0\" encoding=\" UTF-8\" standalone=\" no\" ?>\r\n "
169
- " <?xml-stylesheet type=\" text/xsl\" href=\" "
170
- xslt
171
- " \" ?>\r\n <menuLib>\r\n " ;
172
- " <menuLib>\r\n " ;
189
+ serverOut
190
+ <<" <?xml version=\" 1.0\" encoding=\" UTF-8\" standalone=\" no\" ?>\r\n "
191
+ " <?xml-stylesheet type=\" text/xsl\" href=\" "
192
+ xslt
193
+ " \" ?>\r\n <menuLib>\r\n "
194
+ " <sourceURL>"
195
+ <<serverName
196
+ <<" </sourceURL>" ;
173
197
}
174
198
175
199
void pageEnd () {
@@ -242,6 +266,10 @@ bool handleMenu(){
242
266
}
243
267
244
268
void setup (){
269
+ pinMode (LEDPIN,OUTPUT);
270
+ updLed ();
271
+ pinMode (ANALOG_PIN,OUTPUT);
272
+ analogWriteRange (255 );
245
273
// options=&myOptions;//menu options
246
274
Serial.begin (115200 );
247
275
while (!Serial)
@@ -260,16 +288,18 @@ void setup(){
260
288
// Serial.setDebugOutput(0);
261
289
// while(!Serial);
262
290
// delay(10);
263
- wifi_station_set_hostname ((char *)" ArduinoMenu " );
291
+ // wifi_station_set_hostname((char*)serverName );
264
292
Serial.println (" " );
265
293
Serial.println (" Arduino menu webserver example" );
266
294
267
295
SPIFFS.begin ();
268
296
297
+ // WiFi.hostname(serverName);//not good
298
+
269
299
Serial.print (" Connecting to " );
270
300
Serial.println (ssid);
271
301
272
- WiFiMulti.addAP (" r-site.net " , " rsite.2011 " );
302
+ WiFiMulti.addAP (ssid, password );
273
303
while (WiFiMulti.run () != WL_CONNECTED) delay (100 );
274
304
// WiFi.begin(ssid, password);
275
305
// Wait for connection
0 commit comments