I have the following function piece of code in my ESP8266 based NodeMCU:
snprintf ( temp, 800,
"<html>\
<head>\
<meta http-equiv='refresh' content='25'/>\
<title>NodeMCU DHT11 Sensor \and Relay Board</title>\
<style>\
body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
li { margin: 10px 0;}\
</style>\
</head>\
<body>\
<h1>Hello from NodeMCU!</h1>\
<p>Temperature: %02d ℃<br>\
Humidity: %2d %<br></p><ol>\
<li><a href='/control?relay=5&state=%d'>Turn Relay 1 On\/Off</a>\
<li><a href='/control?relay=4&state=%d'>Turn Relay 2 On\/Off</a></ol>\
<p> Uptime: %02d:%02d:%02d </p>\
</body>\
</html>",
t, h, !digitalRead(5), !digitalRead(4), hr, min % 60, sec % 60
);
I want to be able to replace text on with off and vice versa based on the state of pin which comes from digitalRead(5)
. So I don't have to write Turn Relay 1 On/Off and instead I should get the state using digitalRead(pinNum)
and set the text on or off based on state.