Help needed unalbe-to-store-previous-pinstate after reset/powerloss mcu-8266 take-a-look-at-my code

#include <ESP8266WiFi.h>
#include <EEPROM.h>
#define led0 D0
#define led1 D1
#define led2 D2
#define led3 D3
#define led4 D4
#define led5 D5
#define led6 D6
#define led7 D7
#define led8 D8
WiFiClient client;
WiFiServer server(80);

const char* ssid = "ADMIN-PC"; // Replace with SSID
const char* password = "1122334455"; // Replace with WiFi Password

IPAddress subnet(255,0,0,0); // Subnet Mask
IPAddress gateway(10,128,160,209); // Default Gateway
IPAddress local_IP(10,128,160,120); // Static IP Address for ESP8266

void setup()
{
Serial.begin(115200);

if (WiFi.config(local_IP, gateway, subnet))
{
Serial.println("Static IP Configured");
}
else
{
Serial.println("Static IP Configuration Failed");
}

WiFi.begin(ssid, password);

Serial.print("Connecting...");

while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
{
Serial.println("..");
Serial.println("WiFi Connected! IP address:");
Serial.println(WiFi.localIP());
server.begin();
}
pinMode(led0, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);

digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led8, HIGH);
}
void loop()
{

// put your main code here, to run repeatedly:
client = server.available(); //Gets a client that is connected to the server and has data available for reading.
if (client == 1)
{
String request = client.readStringUntil('\n');
Serial.println(request);
request.trim();
if(request == "GET /led0on HTTP/1.1")
{
digitalWrite(led0, LOW);
}
if(request == "GET /led0off HTTP/1.1")
{
digitalWrite(led0, HIGH);
}
if(request == "GET /led1on HTTP/1.1")
{
digitalWrite(led1, LOW);
}
if(request == "GET /led1off HTTP/1.1")
{
digitalWrite(led1, HIGH);
}
if(request == "GET /led2on HTTP/1.1")
{
digitalWrite(led2, LOW);
}
if(request == "GET /led2off HTTP/1.1")
{
digitalWrite(led2, HIGH);
}
if(request == "GET /led3on HTTP/1.1")
{
digitalWrite(led3, LOW);
}
if(request == "GET /led3off HTTP/1.1")
{
digitalWrite(led3, HIGH);
}
if(request == "GET /led4on HTTP/1.1")
{
digitalWrite(led4, LOW);
}
if(request == "GET /led4off HTTP/1.1")
{
digitalWrite(led4, HIGH);
}
if(request == "GET /led5on HTTP/1.1")
{
digitalWrite(led5, LOW);
}
if(request == "GET /led5off HTTP/1.1")
{
digitalWrite(led5, HIGH);
}
if(request == "GET /led6on HTTP/1.1")
{
digitalWrite(led6, LOW);
}
if(request == "GET /led6off HTTP/1.1")
{
digitalWrite(led6, HIGH);
}
if(request == "GET /led7on HTTP/1.1")
{
digitalWrite(led7, LOW);
}
if(request == "GET /led7off HTTP/1.1")
{
digitalWrite(led7, HIGH);
}
if(request == "GET /led8on HTTP/1.1")
{
digitalWrite(led8, LOW);
}
if(request == "GET /led8off HTTP/1.1")
{
digitalWrite(led8, HIGH);
}
if(request == "GET /ledallon HTTP/1.1")
{
digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
}
if(request == "GET /ledalloff HTTP/1.1")
{
digitalWrite(led0, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
digitalWrite(led7, HIGH);
digitalWrite(led8, HIGH);
}
}
}

Welcome to the forum

Why did you start a topic in the Uncategorised category of the forum when its description is

:warning: DO NOT CREATE TOPICS IN THIS CATEGORY :warning:

Your topic has been moved to the Programming category

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

sorry for the mistake i am new to this forum so thats why i made a mistake tried to edit the post pls let me know if it is ok?

Show your code that includes your attempt to store the pin states.

Looks OK now

1 Like

i surf the internet but found nothing all topics are with a push button which is unable to understand pls alter this code and help

perhaps you could exp0lain:
1: what you expect it to do and
2: what it is doing

it is turning on lights on movie interval but on device reset, it is not retaining pins previos state . so need some alteration in code to store its pins last state incase of reset/powerloss.......

following a reset (or power down) the arduino runs setup() - as its supposed to do.
And in setup you set all the lights high.

you need a storage location that retains data during power down.

Like this

or

Save the data each time the lights condition is required to change, and read the value when the system starts up.

You may need a button to set the condition that setup() presently provides.

As the eeprom has a limit (100,000) to the number of writes to a cell, so if that will be a problem you could alternatively use an external sd card

Your first link might not quite be applicable; as far as I understand from the topic title, it's and ESP8266.

But OP should have enough ammunition to start understanding what the options are.

Thanks @sterretje I linked to the wrong tab; I've added the one for the 8266
Anyway I prefer the sd card solution

I've just seen this which could be another alternative

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.