0

I'm trying to write web server code. However, I am having trouble with part of it.

Currently, to get it to save a bool variable I have it use a pin, as when I ran the code without it, after the page refreshes it resets the variable to its original value.

How do I get it to save the variable in this code without it using the pin?

digitalWrite (equalPin, server.arg("equal").toInt());
char equalText[80];
if(equalState) {
  strcpy(equalText, "priority is equal. <a href=\"/?equal=0\">Deactivate</a>");
  equalState = false;
} else {
  strcpy(equalText, "priority is not equal. <a href=\"/?equal=1\">Activate</a>");
  equalState = true;
}
equalState = digitalRead(equalPin);

I also have several over copies of this for different pages but if I change 1 of them they all change and reset after 10 seconds.

The code follows the example on this site.

4
  • so you want to set it or leave it as is? in if and else you change it and then you revert to the value before if and else. perhaps learn coding first. – Juraj Apr 22 '18 at 10:14
  • I want it to set it then potentially change again in the future. I remeber doing it in the past but ive completely forgotten how. How do I stop it from reverting? – Apple Apr 22 '18 at 10:26
  • I can't understand what you're asking. Perhaps someone else can, but perhaps writing the question more clearly would help you get more responses. Consider a minimal, complete, verifiable example (Google to find what that is). – Mark Smith Apr 22 '18 at 11:40
  • What are your trying to achieve? The code you linked to presumably works fine. Please, state clearly the purpose of your modifications. – Edgar Bonet Apr 22 '18 at 13:41
1

same code snippet without using pin

char equalText[80];

if (equalState){
  strcpy(equalText, "priority is equal. <a href=\"/?equal=0\">Deactivate</a>");
  equalState = false;
}
else {
  strcpy(equalText, "priority is not equal. <a href=\"/?equal=1\">Activate</a>");
  equalState = true;
}
equalState = server.arg("equal").toInt();

but it does not make much sense to set the value if you already switched the state based on it's previous value

1
  • That seems to have worked it just doesnt auto refresh the page anymore but thats fine. – Apple Apr 22 '18 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.