I'm trying to make a Wi-Fi controlled thermostat using a Wi-Fi Uno Rev2, a relay and a temperature sensor. The wiring is pretty basic and so far works fine, but I'm having issues coding the web interface. Specifically, I am trying to use a form to set up programs to change the thermostat's set temperature, at certain times of day, on certain days.
My base code is adapted from an example sketch included with the WifiNina library, SimpleWebServerWifi, along with some code I cut and pasted from example sketch TimeNTP_ESP8266WiFi to retrieve time, plus a lot of container variables and general code that I added myself.
In particular, the code from SimpleWebServerWifi uses a string named currentLine to hold the URL, and then does things like
if (currentLine.endsWith("GET /L")) {
digitalWrite(9, LOW); // GET /L turns the LED off
}
...I've successfully adapted this code to do whatever I define by clicking links, but forms seem to be a whole other beast. I'm using form method = get, so that whatever the user selects will come up in the URL, and then trying to scrape it with, for example, this
bagofholding = currentLine.indexOf('S', 6);
if ((currentLine.indexOf('u', 6)-bagofholding) ==1) {
Sunday = 1;}
(bagofholding is a generic integer container that I reuse when I just want to hold a value briefly.) The form should return Su (among other things) in the URL if the Sunday checkbox was checked, and so what I'm trying to do here is read for those two letters consecutively and mark the variable "Sunday" as 1 if they are there.
Unfortunately, Serial monitor seems to be unhappy trying to debug my code while everything else is going - it crashes on me after a little while, making it hard to go back and see what values it's spitting out where, but I set up a makeshift table that shows up on the web page that should show the values of the program container variables (Sunday-Saturday, slots 1-4 for each, plus a set designated with a T for temperature) - but these remain at 0, telling me that no value is being committed to them.
My best guess is that I'm either not properly capturing the full URL when I submit the form or that I'm not properly searching the resulting string for my data; in either case I could desperately use some help figuring out what to do.
I've attached my sketch - my apologies in advance that it's a little bit messy, and my thanks in advance for any help that anyone can offer.
Wifi_Uno_Thermostat3.ino (20.9 KB)