Giter Site home page Giter Site logo

projetsdiy / esp8266-webserver-tutorials Goto Github PK

View Code? Open in Web Editor NEW
95.0 18.0 62.0 263 KB

How to use ESP8266 as a Web Server

Home Page: http://www.diyprojects.io/category/esp8266/esp8266-interface-html-server-web/

License: MIT License

HTML 80.99% C++ 19.01%
esp8266 spiffs arduino dht22 bmp180 webserver wemos-d1-mini

esp8266-webserver-tutorials's People

Contributors

projetsdiy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp8266-webserver-tutorials's Issues

Tables with rows Editables

Good morning
I'm learning a lot thanks to this tutorial. I would like to make a modification in the bootstrap table to add 2 functions:

  1. That the rows were editable.
  2. An icon appears to send that data back to the nodemcu

My level of Jquery and bootstrap is a beginner. I have tried a number of modifications but without success:

    <script>
  $ .fn.editable.defaults.mode = 'inline';
 .........
    </script>


  <th data-field = "mesure" data-editable = "true" data-align = "left" data-sortable = "true" data-formatter = "labelFormatter"> Mesure </ th>

           $ ('# mesure'). editable ({
               mode: 'inline',
           });

Could you give me some indication of how to build this modification?

Thank you for your work ¡¡¡

Not working on ESP8266-01

Can someone help me with this, i stripped down the code to work to run on the ESp8266 -01 , It does not seem to work. I am using an sr04 ultra-sonic sensor.
the same code works on the lolin nodemcu v3

`
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

#include <FS.h>
#include <TimeLib.h>
#include <NtpClientLib.h>
#include <ArduinoJson.h>

#define ssid "KharisHome" // WiFi SSID
#define password "De_deziner1" // WiFi password
#define trig 0
#define echo 2 // Broche du DHT / DHT Pin
#define HISTORY_FILE "/history.json"
float t = 0 ;

int sizeHist = 84 ; // Taille historique (7h x 12pts) - History size

const long intervalHist = 1000 * 60 * 5; // 5 mesures / heure - 5 measures / hours

// Création des objets / create Objects

ESP8266WebServer server ( 80 );

StaticJsonBuffer<10000> jsonBuffer; // Buffer static contenant le JSON courant - Current JSON static buffer
JsonObject& root = jsonBuffer.createObject();
JsonArray& timestamp = root.createNestedArray("timestamp");
JsonArray& hist_t = root.createNestedArray("t");

char json[10000]; // Buffer pour export du JSON - JSON export buffer

void sendMesures() {
String json = "{"t":"" + String(t) + ""}";

server.send(200, "application/json", json);
Serial.println("Send measures");
}

void sendTabMesures() {
double temp = root["t"][0]; // Récupère la plus ancienne mesure (temperature) - get oldest record (temperature)
String json = "[";
json += "{"mesure":"Température","valeur":"" + String(t) + "","unite":"°C","glyph":"glyphicon-indent-left","precedente":"" + String(temp) + ""}";
json += "]";
server.send(200, "application/json", json);
Serial.println("Send data tab");
}

void sendHistory(){
root.printTo(json, sizeof(json)); // Export du JSON dans une chaine - Export JSON object as a string
server.send(200, "application/json", json); // Envoi l'historique au client Web - Send history data to the web client
Serial.println("Send History");
}

void loadHistory(){
File file = SPIFFS.open(HISTORY_FILE, "r");
if (!file){
Serial.println("Aucun historique existe - No History Exist");
} else {
size_t size = file.size();
if ( size == 0 ) {
Serial.println("Fichier historique vide - History file empty !");
} else {
std::unique_ptr<char[]> buf (new char[size]);
file.readBytes(buf.get(), size);
JsonObject& root = jsonBuffer.parseObject(buf.get());
if (!root.success()) {
Serial.println("Impossible de lire le JSON - Impossible to read JSON file");
} else {
Serial.println("Historique charge - History loaded");
root.prettyPrintTo(Serial);
}
}
file.close();
}
}

void saveHistory(){
Serial.println("Save History");
File historyFile = SPIFFS.open(HISTORY_FILE, "w");
root.printTo(historyFile); // Exporte et enregsitre le JSON dans la zone SPIFFS - Export and save JSON object to SPIFFS area
historyFile.close();
}

void setup() {
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);

NTP.onNTPSyncEvent([](NTPSyncEvent_t error) {
if (error) {
Serial.print("Time Sync error: ");
if (error == noResponse)
Serial.println("NTP server not reachable");
else if (error == invalidAddress)
Serial.println("Invalid NTP server address");
}
else {
Serial.print("Got NTP time: ");
Serial.println(NTP.getTimeDateString(NTP.getLastNTPSync()));
}
});
// Serveur NTP, decalage horaire, heure été - NTP Server, time offset, daylight
NTP.begin("pool.ntp.org", 0, true);
NTP.setInterval(60000);
delay(500);

Serial.begin ( 115200 );

WiFi.begin ( ssid, password );
int tentativeWiFi = 0;
// Attente de la connexion au réseau WiFi / Wait for connection
while ( WiFi.status() != WL_CONNECTED ) {
delay ( 500 ); Serial.print ( "." );
tentativeWiFi++;
if ( tentativeWiFi > 20 ) {
ESP.reset();
while(true)
delay(1);
}
}
// Connexion WiFi établie / WiFi connexion is OK
Serial.println ( "" );
Serial.print ( "Connected to " ); Serial.println ( ssid );
Serial.print ( "IP address: " ); Serial.println ( WiFi.localIP() );

if (!SPIFFS.begin()) {
Serial.println("SPIFFS Mount failed"); // Problème avec le stockage SPIFFS - Serious problem with SPIFFS
} else {
Serial.println("SPIFFS Mount succesfull");
loadHistory();
}
delay(50);

server.on("/tabmesures.json", sendTabMesures);
server.on("/mesures.json", sendMesures);
//server.on("/gpio", updateGpio);
server.on("/graph_temp.json", sendHistory);

server.serveStatic("/js", SPIFFS, "/js");
server.serveStatic("/css", SPIFFS, "/css");
server.serveStatic("/img", SPIFFS, "/img");
server.serveStatic("/", SPIFFS, "/index.html");

server.begin();
Serial.println ( "HTTP server started" );

Serial.print("Uptime :");
Serial.println(NTP.getUptime());
Serial.print("LastBootTime :");
Serial.println(NTP.getLastBootTime());
}

void loop() {
// put your main code here, to run repeatedly:
server.handleClient();

float duration, distance;

digitalWrite(trig, LOW);
//
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
//
duration = pulseIn(echo, HIGH);
//
distance = duration / 58;
Serial.print(distance);
Serial.println(" cm");
delay(100);
t = duration / 58;
//t=34+t;
if ( isnan(t) ) {
//Erreur, aucune valeur valide - Error, no valid value
} else {
addPtToHist();
}
//delay(5);
}

void addPtToHist(){

//Serial.println(currentMillis - previousMillis);
long int tps = NTP.getTime();
//Serial.println(NTP.getTime());
if ( tps > 0 ) {
timestamp.add(tps);
hist_t.add(double_with_n_digits(t, 1));

  //root.printTo(Serial);
  if ( hist_t.size() > sizeHist ) {
    //Serial.println("efface anciennes mesures");
    timestamp.removeAt(0);
    hist_t.removeAt(0);
  ;
  }
  //Serial.print("size hist_t ");Serial.println(hist_t.size());
 // calcStat();
  delay(100);
  saveHistory();
  //root.printTo(Serial);  

}
}```

Using datetime for larger period of data

What a great tutorial!

I have looked everywhere but could not find an answer for this problem.
I have more than one day of data. The grapics starts over at the left side as there is the time 00:00

Now, how can I use the date and time for the hAxis?
If I simply add a row “datetime” I get an error “invallid type”.

Can you please help me?

Issue with Tutorial5

Hi

I have some issues with the Tutorial5.
Data are stored in the JSON file:
{"timestamp":[1519303055,1519303075,1519303095],"t":[25.4,25.4,25.4],"h":[19.8,20.2,20.1],"pa":[1050,1050,1050],"bart":[],"barh":[]}

Graph is populated with the values and work as expected until a reboot of the ESP!
When the ESP reboots the file is read and in the loadHistory() function I see that the file is read with the root.prettyPrintTo(Serial);

BUT the graph never get the old data, program starts with a reading of the current temp/humidity and overwrites the file so I lose all the history.

Have anyone else experienced this and if so solved the read-back from file to the current buffer?

save & load json

Hello,
thanks for your great tutorial. It's really good.
I have an issue with the json load.
It loads the json fine, but in another root... so, the rest of the app can't use it.
is it a mistake ?
if no, did I miss something ?
if yes, how to fix it ? ;)
Thanks !!
Francois (greetings from france)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.