Giter Site home page Giter Site logo

basicwebserver's Introduction

Works with both Arduino IDE and PlatformIO

I find that when creating pretty much any new project with an ESP8266 or ESP32 I use this sketch as a starting point, so I have published it here in case it is of any use/interest to anyone else (I also hope that people will offer improvements/suggestions as I am not a professional programmer by any stretch of the imagination).
It is not all my own work, just something I have put together for my own use from many sources.

It is the easiest way I have found to serve web pages with control buttons, updating information, a log of activity BTW - This sketch will automatically adjust to running on either a ESP8266 or a ESP32 For a more advanced option for showing updating info see: https://github.com/alanesq/misc/blob/main/VeryBasicWebserver.ino

It has built in support for sending emails, getting the real time from NTP, a simple Oled display menu system, GSM board support and OTA updating.

Note: It does not work with the latest esp32 Arduino addin (i.e. v2) as ESP_Wifimanager at least for me just gets an ip address of 255.255.255.255 for some reason

The sketch as it is will first create a wifi access point named "espserver", you need to connect to this with the password "12345678" and you will then be able to enter your wifi network details so it is then able to connect to it (it uses the Autoconnect library to do this which is included in the above file). Once connected to your network you should be able to view a similar web page to the image above (you will need to find out what ip address it is using from your router or by viewing the terminal window in the Arduino IDE).

If you look in the procedure "handleRoot", the lower part is where it creates any control buttons and the top part is where it performs any actions when the buttons are pressed. Any information you want to update (e.g. sensor status) are put in the procedure "data" as this is then automatically updated every few seconds. It uses AJAX to update the info., this is not done in the conventional way where variable data is passed but instead passes complete lines of text, it may not be elegant but it makes changing what information is displayed much easier as all you have to do is modify what info handleData() sends.

You can then add your own code to the "loop" section to perform whatever tasks you wish...

ESP8266 addon package = v2.5.2 (I find problems if useing a newer version) from http://arduino.esp8266.com/stable/package_esp8266com_index.json

It now suports OTA updates (this can be disabled in the settings if preferred) Note - As at least some basic form of security you first need to enter a password to enable ota Then access with http://x.x.x.x/ota

If you have several projects there is a HTML page here which can be used to give a menu of them all https://github.com/alanesq/CameraWifiMotion/blob/master/misc/menu-of-projects.htm

basicwebserver's People

Contributors

alanesq avatar

Stargazers

frnck37 avatar Emilio P Egido avatar Tom Windell avatar Vladimir Jucov avatar Andrew B. Powers avatar  avatar Takurua avatar  avatar ERR avatar bonedaddy avatar

Watchers

 avatar

Forkers

bonedaddy elmo40

basicwebserver's Issues

redefinition of 'bool wifiok'

Redefinition of 'bool wifiok' in wifi.h (line 45):
bool wifiok = 0; // flag if wifi connection is ok

First definition in BasicWebServer.ino (line 98):
bool wifiok = 0; // flag if wifi connection is ok

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.