ESP32 web server HTTP learning with BME280

I need a web server on esp32/8266 to work as user interface for config wifi(mode, ssid, pwd) as well we some parameter useful for program usage, and then store it in flash of the chip.

I used to use PyBBIO web server on bone or pi, without knowing the basic. Now I have to go into it and find a good one on esp. I have look into the lib of esp32 arduino, there is a simple wifiserver, but too simple and I lack of HTTP knowage.
Here is very good one: https://startingelectronics.org/tutorials/arduino/ethernet-shield-web-server-tutorial/basic-web-server/

and for ESP32 webserver,Then I found this:


so he used a library called https://github.com/bbx10/WebServer_tng , which works on 8266 and ESP32, and he also has a sd webserver, seems reallly interesting
https://github.com/bbx10/WebServer_tng/blob/master/examples/SDWebServer/SDWebServer.ino

I tried his example, http://educ8s.tv/wp-content/uploads/2017/11/ESP32-Web-Server.zip
it did not compile, and come with an error on no matching function for call to 'Adafruit_BME280::Adafruit_BME280(int, int)' I did not understand why for quite a long time, and struggle with adafruit lib for IIC, to find a way to assign the IIC pins. I finally found that he use another modified adafruit BME280 lib https://github.com/Takatsuki0204/BME280-I2C-ESP32

I tried to understand what he modified in the cpp:
in the private function:
orignal is :
Adafruit_BME280::Adafruit_BME280()
: _cs(-1), _mosi(-1), _miso(-1), _sck(-1)
{ }

He changed to :
Adafruit_BME280::Adafruit_BME280(uint8_t sda, uint8_t scl)
: _cs(-1), _mosi(-1), _miso(-1), _sck(-1), pinSDA(sda), pinSCL(scl)
{ }

This explain how he got the function to use Adafruit_BME280(int, int)


The in the begin he also change to :
bool Adafruit_BME280::begin(uint8_t addr)
{
_i2caddr = addr;
// init I2C or SPI sensor interface
if (_cs == -1) {
// I2C
Wire.begin(pinSDA, pinSCL);
} else {
digitalWrite(_cs, HIGH);
pinMode(_cs, OUTPUT);
if (_sck == -1) {
// hardware SPI
SPI.begin();
} else {
// software SPI
pinMode(_sck, OUTPUT);
pinMode(_mosi, OUTPUT);
pinMode(_miso, INPUT);
}
}

This is how he got the begin with assigned IIC pins.

So, I removed the original one of adfruit to avoid conflict. and install Takatsuki version, modi the SDA to 4 and SCL to 15, BME280 works fine on my heltec 8266 board.
But in the latest version of adafruit lib, there is a way to assign pins, just I did not understand how this is done:
bool Adafruit_BME280::begin(uint8_t addr, TwoWire *theWire)
{
_i2caddr = addr;
_wire = theWire;
return init();
}



Then run the server again(with modi on IIC pins), it works correctly....


Other web server lib
fro IOTsharing: https://github.com/nhatuan84/esp32-webserver

留言

這個網誌中的熱門文章

Meshtastic 03 adding GPS on TTGO lora32 V2

GeoSetter how to add geotag on to pictures, and export to google earth as kmz

AIS0. understanding AIS NMEA 0183: How it's coded