Thanks to Peter (katz), I "flattened" the code a bit and made a multi-tab project (attached.) I also set the slider to control the NodeMCU pin #2 to vary the flash rate of the LED on the NodeMCU board (by LoLin.)
By breaking the project into 3 tabs (the Notes.h tab is just for word processing stuff...) it is easier to use for training. The active tabs are:
[*] AJAX.ino
[*] functions.h
[*] javascript.h
Note: You will need the
Streaming.h library from hereMultiTab Arduino projects really simplify what is happening, IMO. Here is the main AJAX tab:
Code: Select all#include "./functions.h"
#include <Streaming.h> // http://arduiniana.org/libraries/streaming/
const char* ssid = "**SSID*"; // ERASE prior to publishing
const char* password = "wifipasswd"; // "" ditto
int LED = 2; // NodeMCU by LoLin
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(19200); delay(100);
Serial << (F("... Attempting to log into router... \r\n"));
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(500);
WiFi.mode(WIFI_STA);
Serial << (F("\n\nBOOTING ESP8266 ..."));
Serial << (F("Connected to ")) << ssid << endl;
Serial << (F("Station IP address: ")) << WiFi.localIP() << endl;
server.on("/", handleWebsite);
server.on("/xml", handleXML);
server.on("/setESPval", handleESPval);
server.begin();
}
void loop() {
server.handleClient();
if (millis() > wait000) {
buildXML();
wait000 = millis() + 1000UL;
}
if (millis() > wait001) { // slider0 controls LED blink rate
digitalWrite(LED, !digitalRead(LED));
wait001 = millis() + ESPval[0];
}
}
Non-members can download here withoutsign-up.Ray