Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
node: Add reset option for seed
Browse files Browse the repository at this point in the history
- Reset the value in EEPROM Memory through(/reset)
  • Loading branch information
harshithpabbati authored and vibhoothi committed Jan 23, 2020
1 parent b272b55 commit 3f92c4e
Showing 1 changed file with 53 additions and 9 deletions.
62 changes: 53 additions & 9 deletions node/node.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,40 @@
#include <ESP8266WebServer.h>
#include <time.h>
#include <Ticker.h>
#include <EEPROM.h>

#define ull unsigned long long

Ticker blinker;
ESP8266WebServer server(80);

const char* password = "";
const char* password
char ssid[100];
unsigned long long a, c, m, seed;
void change_seed(){
seed = (seed%m) * (a%m);
seed = seed%m;
ull a, c, m, addr;

ull change_seed(ull seed) {
seed = (seed % m) * (a % m);
seed = seed % m;
seed += c;
seed %= m;
return seed;
}

ull get_seed() {
ull seed;
EEPROM.get(addr, seed);
return seed;
}

void write_seed(ull seed){
EEPROM.put(addr, seed);
EEPROM.commit();
}

void changeWifi(){
change_seed();
void changeWifi() {
ull seed = get_seed();
seed = change_seed(seed);
write_seed(seed);
sprintf(ssid, "amFOSS_%d", seed);
WiFi.softAP(ssid, password);
Serial.println(ssid);
Expand All @@ -26,13 +45,38 @@ void changeWifi(){
void setup() {
delay(1000);
Serial.begin(115200);
Serial.print("Initial Setup");
change_seed();
EEPROM.begin(512);
Serial.println("Initial Setup");
ull seed = get_seed();
sprintf(ssid, "amFOSS_%d", seed);
WiFi.softAP(ssid, password);
Serial.println(ssid);
Serial.println(WiFi.softAPIP());
server.on("/reset", HTTP_GET, reset_EEPROM);
server.begin();
blinker.attach(300, changeWifi);
}

void reset_EEPROM(){
Serial.println("RESETTING");
blinker.detach();
EEPROM.put(addr, 1000);
String response = "<!DOCTYPE html>\n";
response += "<html>\n";
response += "<head>\n";
response += "<title>Wifi Control Page</title>\n";
response += "</head>\n";
response += "<body>\n";
response += "<h1>Node Status</h1>\n";
response += "<p>EEPROM seed set to 1000</p>\n";
response += "</body>\n";
response += "</html>\n";
server.send(200, "text/html", response);
delay(1000);
changeWifi();
blinker.attach(300, changeWifi);
}

void loop() {
server.handleClient();
}

0 comments on commit 3f92c4e

Please sign in to comment.