@@ -36,8 +36,20 @@ extern "C" {
3636
3737using namespace Menu ;
3838
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" ;
4153#ifdef DEBUG
4254 // on debug mode I put aux files on external server to allow changes without SPIFF update
4355 // 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) {
7688}
7789
7890int ledCtrl=LOW;
91+ #define LEDPIN LED_BUILTIN
92+ void updLed () {
93+ digitalWrite (LEDPIN,!ledCtrl);
94+ }
7995
80- TOGGLE (ledCtrl,setLed," Led: " ,doNothing,noEvent ,noStyle// ,doExit,enterEvent,noStyle
96+ TOGGLE (ledCtrl,setLed," Led: " ,updLed,enterEvent ,noStyle// ,doExit,enterEvent,noStyle
8197 ,VALUE(" On" ,HIGH,doNothing,noEvent)
8298 ,VALUE(" Off" ,LOW,doNothing,noEvent)
8399);
@@ -97,13 +113,17 @@ CHOOSE(chooseTest,chooseMenu,"Choose",doNothing,noEvent,noStyle
97113 ,VALUE(" Last" ,-1 ,doNothing,noEvent)
98114);
99115
116+ int timeOn=50 ;
117+ void updAnalog () {
118+ analogWrite (ANALOG_PIN,map (timeOn,0 ,100 ,0 ,PWMRANGE));
119+ }
120+
100121// the menu
101- int timeOn;
102122MENU (mainMenu," Main menu" ,doNothing,noEvent,wrapStyle
103123 ,SUBMENU(setLed)
104124 ,OP(" Action A" ,action1,enterEvent)
105125 ,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)
107127 ,SUBMENU(selMenu)
108128 ,SUBMENU(chooseMenu)
109129);
@@ -124,37 +144,39 @@ NAVROOT(nav,mainMenu,MAX_DEPTH,serial,out);
124144void webSocketEvent (uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
125145 switch (type) {
126146 case WStype_DISCONNECTED:
127- USE_SERIAL.printf (" [%u] Disconnected!\n " , num);
147+ // USE_SERIAL.printf("[%u] Disconnected!\n", num);
128148 break ;
129149 case WStype_CONNECTED: {
130150 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);
132152 webSocket.sendTXT (num, " console.log('ArduinoMenu Connected')" );
133153 }
134154 break ;
135155 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);
137157 nav.async ((const char *)payload);// this is slow!!!!!!!!
138158 break ;
139159 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;
144166 uint16_t id=*(uint16_t *) payload++;
145167 idx_t len=*((idx_t *)++payload);
146168 idx_t * pathBin=(idx_t *)++payload;
147169 const char * inp=(const char *)(payload+len);
148- Serial<<" id:" <<id<<endl;
170+ // Serial<<"id:"<<id<<endl;
149171 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;
152174 // StringStream inStr(inp);
153175 // while(inStr.available())
154176 nav.doInput (inp);
155177 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;
158180 }
159181 break ;
160182 }
@@ -164,12 +186,14 @@ void pageStart() {
164186 server.sendHeader (" Cache-Control" ," no-cache, no-store, must-revalidate" );
165187 server.sendHeader (" Pragma" ," no-cache" );
166188 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>" ;
173197}
174198
175199void pageEnd () {
@@ -242,6 +266,10 @@ bool handleMenu(){
242266}
243267
244268void setup (){
269+ pinMode (LEDPIN,OUTPUT);
270+ updLed ();
271+ pinMode (ANALOG_PIN,OUTPUT);
272+ analogWriteRange (255 );
245273 // options=&myOptions;//menu options
246274 Serial.begin (115200 );
247275 while (!Serial)
@@ -260,16 +288,18 @@ void setup(){
260288 // Serial.setDebugOutput(0);
261289 // while(!Serial);
262290 // delay(10);
263- wifi_station_set_hostname ((char *)" ArduinoMenu " );
291+ // wifi_station_set_hostname((char*)serverName );
264292 Serial.println (" " );
265293 Serial.println (" Arduino menu webserver example" );
266294
267295 SPIFFS.begin ();
268296
297+ // WiFi.hostname(serverName);//not good
298+
269299 Serial.print (" Connecting to " );
270300 Serial.println (ssid);
271301
272- WiFiMulti.addAP (" r-site.net " , " rsite.2011 " );
302+ WiFiMulti.addAP (ssid, password );
273303 while (WiFiMulti.run () != WL_CONNECTED) delay (100 );
274304 // WiFi.begin(ssid, password);
275305 // Wait for connection
0 commit comments