NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#include <EEPROM.h>
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h> //https://github.com/tzapu/WiFiManager
//http client libraries
#include <Arduino.h>

#include <ESP8266HTTPClient.h>
#define USE_SERIAL Serial
int id=0,pass=0,val=0,sts=0,othrs=0,vals=0,usid=0,a,stid=0,stc=0;
int p1=1,p2=1,p3=1,p4=1;
String payload,cname;
int test=0;
WiFiManager wifiManager;
void EEPROMWriteInt(int p_address, int p_value)
{
EEPROM.begin(50);
byte lowByte = ((p_value >> 0) & 0xFF);
byte highByte = ((p_value >> 8) & 0xFF);
EEPROM.write(p_address, lowByte);
EEPROM.write(p_address + 1, highByte);
EEPROM.commit();
}

//This function will read a 2 byte integer from the eeprom at the specified address and address + 1
unsigned int EEPROMReadInt(int p_address)
{
EEPROM.begin(50);
byte lowByte = EEPROM.read(p_address);
byte highByte = EEPROM.read(p_address + 1);
EEPROM.commit();
return ((lowByte << 0) & 0xFF) + ((highByte << 8) & 0xffFF);
}
void setup() {

pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);

// put your setup code here, to run once:

Serial.begin(115200);

Serial.println();
//WiFiManager
//Local intialization. Once its business is done, there is no need to keep it around

//reset saved settings

// wifiManager.resetSettings();
// EEPROMWriteInt(10, 0);
//EEPROMWriteInt(20, 0);
//EEPROMWriteInt(30, 0);

//set custom ip for portal
//wifiManager.setAPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));

//fetches ssid and pass from eeprom and tries to connect
//if it does not connect it starts an access point with the specified name
//here "AutoConnectAP"
//and goes into a blocking loop awaiting configuration

pass = EEPROMReadInt(10);
Serial.println("pass:");
Serial.println(pass);
id = EEPROMReadInt(20);
Serial.println("id");
Serial.println(id);
usid = EEPROMReadInt(30);
Serial.println("usid");
Serial.println(usid);
if(id==usid&&id==pass&&pass==usid)
{id=0;usid=0;pass=0;}
if(id==usid)
{id=0;usid=0;}
if(pass==0)
{ wifiManager.resetSettings();
wifiManager.autoConnect();
a = wifiManager.getusid();
Serial.println("Wrote Usid:");
Serial.println(a);
EEPROMWriteInt(10, a);
Serial.println("EEPROM");
Serial.println(EEPROMReadInt(10));
pass=a;
}
else
{
wifiManager.setTimeout(200);
if(!wifiManager.autoConnect()&&pass==0) {
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(5000);
}
}

//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");

for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...n", t);
USE_SERIAL.flush();
delay(1000);
}
cname = wifiManager.getcid();
}
void work()
{

if(p1==1)
{
digitalWrite(D0, HIGH);
}
else if(p1==0)
{
digitalWrite(D0, LOW);
}
if(p2==1)
{
digitalWrite(D1, HIGH);
}
else if(p2==0)
{
digitalWrite(D1, LOW);
}
if(p3==1)
{
digitalWrite(D2, HIGH);
}
else if(p3==0)
{
digitalWrite(D2, LOW);
}

if(p4==1)
{
digitalWrite(D3, HIGH);
}
else if(p4==0)
{
digitalWrite(D3, LOW);
}
}
void loop() {

HTTPClient http;
if(stc==0)
{

String kresource = String("http://iotsistem.000webhostapp.com/iot.php?id=") + id + String("&pass=") + pass + String("&val=") + val + String("&sts=") + sts + String("&othrs=") + othrs + String("&vals=") + vals + String("&usid=") + usid+ String("&name=") + cname+ String("&p1=") + p1+ String("&p2=") + p2+ String("&p3=") + p3+ String("&p4=") + p4;
Serial.println(kresource);
http.begin(kresource);
int httpCode = http.GET();
if(httpCode == HTTP_CODE_OK) {
payload = http.getString();
Serial.println(payload);
}
else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %sn", http.errorToString(httpCode).c_str());
/* if(test>400)
if (!wifiManager.startConfigPortal()) {
test=0;
Serial.println("failed to connect and hit timeout");
delay(3000);
//reset and try again, or maybe put it to deep sleep
ESP.reset();
delay(5000);
}*/
}
http.end();
if(payload=="")
{work();}
if(pass!=0&&id!=0)
{stc=1;}
if(payload.charAt(0)=='!')
{
bool s=false;
int j=0;
int k=0;
int p=0,mn=0;
char buf[30];
while(payload.charAt(j)!='#')
{
j++;
if(payload.charAt(j)!='*')
{
buf[p]=payload.charAt(j);
p++;
Serial.println(buf);
Serial.println(payload.charAt(j));
}
else if(payload.charAt(j)=='*')
{
k++;
if(k==1)
{
if(buf[0]=='r')
{wifiManager.resetSettings();
wifiManager.autoConnect();
a = wifiManager.getusid();
Serial.println("Wrote Usid:");
Serial.println(a);
EEPROMWriteInt(10, a);
Serial.println("EEPROM");
Serial.println(EEPROMReadInt(10));
pass=a;
usid=0;
id=0;

}
if(pass!=0&&buf[0]=='1')
{
mn=1;
p=0;
memset(buf, 0, sizeof(buf));
}
if(pass!=0&&buf[0]=='2')
{
mn=2;
p=0;
memset(buf, 0, sizeof(buf));
}
}
if(k==1&&pass==0)
{
p=0;
Serial.println(buf);
id=atoi(buf);
Serial.println(id);
EEPROMWriteInt(20, id);
Serial.println("Wrote ID:");
Serial.println(id);
memset(buf, 0, sizeof(buf));

}
else if(k==2&&pass==0)
{
p=0;
Serial.println(buf);
pass=atoi(buf);
EEPROMWriteInt(10, pass);
Serial.println("Wrote pass:");
Serial.println(pass);
Serial.println(pass);
memset(buf, 0, sizeof(buf));
}
else if(k==2&&mn==1)
{
p=0;

id=atoi(buf);
Serial.println(id);
EEPROMWriteInt(20, id);
Serial.println("Wrote ID:");
Serial.println(id);
Serial.println(EEPROMReadInt(20));
memset(buf, 0, sizeof(buf));
}
else if(k==3&&mn==1)
{
p=0;
Serial.println(EEPROMReadInt(30) );

usid=atoi(buf);
EEPROMWriteInt(30, usid);
Serial.println("Wrote pass:");
Serial.println(usid);
Serial.println(usid);
memset(buf, 0, sizeof(buf));
}
else if(k==2&&mn==2)
{
p=0;
p1=atoi(buf);

if(p1==1)
{
digitalWrite(D0, HIGH);
}
else if(p1==0)
{
digitalWrite(D0, LOW);
}
memset(buf, 0, sizeof(buf));
}
else if(k==3&&mn==2)
{
p=0;
p2=atoi(buf);
if(p2==1)
{
digitalWrite(D1, HIGH);
}
else if(p2==0)
{
digitalWrite(D1, LOW);
}
memset(buf, 0, sizeof(buf));
}
else if(k==4&&mn==2)
{
p=0;
p3=atoi(buf);
if(p3==1)
{
digitalWrite(D2, HIGH);
}
else if(p3==0)
{
digitalWrite(D2, LOW);
}
memset(buf, 0, sizeof(buf));
}
else if(k==5&&mn==2)
{
p=0;
p4=atoi(buf);
if(p4==1)
{
digitalWrite(D3, HIGH);
}
else if(p4==0)
{
digitalWrite(D3, LOW);
}
memset(buf, 0, sizeof(buf));
}
else
{

}

}
else{}

}

Serial.println(id);
Serial.println(pass);

}
}
else{
String kresource = String("http://iotsistem.000webhostapp.com/devices/")+id+String(".txt");
Serial.println(kresource);
http.begin(kresource);
int httpCode = http.GET();
if(httpCode == HTTP_CODE_OK) {
payload = http.getString();
Serial.println(payload);
}
else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %sn", http.errorToString(httpCode).c_str());
}

if(payload.charAt(0)=='!')
{
bool s=false;
int j=0;
int k=0;
int p=0,mn=0;
char buf[30];
while(payload.charAt(j)!='#')
{
j++;
if(payload.charAt(j)!='*')
{
buf[p]=payload.charAt(j);
p++;
Serial.println(buf);
Serial.println(payload.charAt(j));
}
else if(payload.charAt(j)=='*')
{
k++;
if(k==1)
{
if(stid!=atoi(buf))
{
stid=atoi(buf);
stc=0;
}
memset(buf, 0, sizeof(buf));

}
}
}
}
}
delay(500);
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.