-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add webserver #98
Add webserver #98
Conversation
You must store the strings in the program memory explicitly, or else, every string gets loaded to RAM at boot. The RAM is getting filled up with strings plus the many Modbus registers from LUNA protocol. I would also recommend using a asynchronous webserver implentacion such as https://github.com/me-no-dev/ESPAsyncWebServer |
Thanks @rjsc! I’ll have a go at implementing the webserver as an asynchronous webserver that saves the HTML and CSS files in SPIFFS, as described in this tutorial. |
@lenvm The Luna2000 registers are not confirmed to need 50k space. For now we can reduce this line in #define MB_RTU_NUM_VALUES 30000 This will make it compile. |
const char* ssidAP = "Battery Emulator"; // maximum of 63 characters; | ||
const char* passwordAP = "123456789"; // minimum of 8 characters; set to NULL if you want the access point to be open |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably move these to USER_SETTINGS.h
As well as a boolean flag to enable/disable the web server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I fully agree with you on both points:
- The
ssid
,password
,ssidAP
andpasswordAP
should be user settings. - There should be a
#define
to determine whether WiFi and the webserver should be active.
I had not implemented these points yet, as I first wanted to figure out how to resolve the issue with the code not compiling for LUNA2000_MODBUS
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matvey83, I have implemented the two points above.
if (current_line.length() == 0) { | ||
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) | ||
// and a content-type so the client knows what's coming, then a blank line: | ||
client.println("HTTP/1.1 200 OK"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to pull the code that generates the response HTML into a separate file, as I imagine it will grow to be quite big eventually.
And also just would be nice to have logic for this separated from the rest of the web server logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree with you on this as well. The folder structure as suggested by the ESP32 Web Server using SPIFFS tutorial uses a data
folder and index.html
and ccs.style
files. This seems a good file structure to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matvey83, due to SPIFFS currently not being supported by Arduino 2.0, I have decided not to proceed an implementation using SPIFFS at this point in time. Therefore there are is also no separate HTML file at this point in time. We can implement this as a future improvement of the code.
Thanks @dalathegreat, that is great to know! In order to also address the other comments in this PR, I am of the opinion that the best way forward is to try to implement the webserver as an asynchronous webserver, with the |
af0327c
to
4961358
Compare
@dalathegreat I have implemented the code as asynchronous webserver, but I have not implemented the code using SPIFFS, as this is currently not supported in Arduino 2.0. I have therefore followed your suggestion and changed the value for the Luna2000 registers from 50k to 30k. |
@lenvm Should we mention that an external antenna should be fitted to the board? |
It's not necessary to connect an external antenna as the board includes a ceramic antenna which is connected by default (the red component marked C3). If an external antenna is to be used, the zero ohm resistor needs to be moved 90 degrees to the alternate position. |
@dalathegreat, can you please review this pull request? In my opinion it is ready to be merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tested this out locally, and it seems like a great feature! Approving this 👍
4961358
to
e37b8f7
Compare
What
This pull request adds webserver functionality.
The devboard creates a WiFi Access Point named
Battery Emulator
that can be connected to using the password "123456789". The IP address of the board as Access Point is printed via Serial. The IP address allows you to connect to the webserver via a webbrowser.The devboard simultaneously connects to an existing network using the
ssid
andpassword
settings provided inwebserver.cpp
. If the connection is successful, the IP address obtained is printed via Serial. This IP address you can connect to via a webbrowser, while you are connected to your local network.The webserver currently displays:
The webserver also allows for updating over the air. Please see the
README.md
file for details.How
The webserver is implemented by using the existing ESP32
Wifi.h
library.The over-the-air capability is implemented by adding 3 new libraries:
The specific commit of each library is added to the
README.md
file of the respective library. Adding the libraries as a git submodule would be an alternative, however some specific changes to make the libraries work in the directory that they are stored in are needed, therefore this approach of storing the commit used in theREADME.md
file is taken, for traceability.Why
It is useful to be able to know the state of the devboard without connecting to it using Serial. Now you are able to check the state of the battery emulation from your couch 😎
This PR opens the possibility to add more webserver functionalities, such as: