Skip to content
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

[SYS] Configuration portal for Ethernet board and HA link to config #1761

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ jobs:
- "airm2m_core_esp32c3"
- "lolin_c3_mini"
- "thingpulse-espgateway"
- "thingpulse-espgateway-ethernet"
runs-on: ubuntu-latest
name: Build with PlatformIO
steps:
Expand Down
24 changes: 16 additions & 8 deletions docs/upload/portal.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
# WiFi and MQTT configuration
# Wifi and MQTT configuration

1technophile marked this conversation as resolved.
Show resolved Hide resolved
## WiFi and MQTT configuration portal for WiFi boards
## Configuration portal

Once loaded into your ESP, and if you don't use the manual configuration, you have to set your network parameters with WiFi Manager portal.

From your smartphone, search for  OpenMQTTGateway or OMG WiFi network and connect to it with the `WifiManager_password` you have defined (the default password is **"your_password"**), or if you are using a device sold by Theengs or the macro `-DWM_PWD_FROM_MAC=true`, the password will be the last eight digits of the device MAC Address with upper case.
From your smartphone, search for  OpenMQTTGateway or OMG_ WiFi network and connect to it with the `WifiManager_password` you have defined (the default password is **"your_password"**), or if you are using a device sold by Theengs or the macro `-DWM_PWD_FROM_MAC=true`, the password will be the last eight digits of the device MAC Address with upper case.
Example, the password would be `CCDDEEFF` for a MAC Address `AABBCCDDEEFF`.
For Theengs devices, the MAC Address can be found on the device sticker, and for all the devices, it is printed on the serial monitor logs.
For the Theengs Plug, the MAC Address can be found on the device sticker, and for all the devices, it is printed on the serial monitor logs.

Once connected to the WiFi, a web page should appear. On Android, you may also have a popup asking you if you want to connect to it without an internet connection. Answer yes always/all the time. If the web page doesn't appear, click on the WiFi Access Point and "Manage router".

::: tip
For boards with an ethernet port you can also access to the Wifi Manager portal through the LAN board IP address.
:::

![WiFi manager menu](../img/OpenMQTTGateway_Wifi_Manager_menu.png)

* Click on Configure WiFi

![WiFi manager parameters](../img/OpenMQTTGateway_Wifi_Manager_enter_parameters.png)

* Select your WiFi
* Set your WiFi password
* Set your WiFi password

::: note
If the board is connected by ethernet, the Wifi and password can be empty. If you fill them the board will use this wifi as a fallback connectivity method.
:::

* Set your MQTT Server IP
* Set your MQTT Server Port (default: 1883)
* Set the MQTT secure connection box to select whether or not the connection should be secure
Expand All @@ -37,12 +46,11 @@ The ESP restart and connect to your network. Note that your credentials are save
Once done the gateway should connect to your network and your broker, you should see it into the broker in the form of the following messages:
```
home/OpenMQTTGateway/LWT Online
home/OpenMQTTGateway/version
```

Note that the web portal appears only on first boot, if you want to configure again the setting you can do a long press on TRIGGER_GPIO or [erase the settings](../use/gateway.md#erase-the-esp-settings).
Note that the web portal appears only on first boot, if you want to configure again the setting you can do a long press on TRIGGER_GPIO, [erase the settings](../use/gateway.md#erase-the-esp-settings) or Reset the configuration from the WebUI.

## MQTT and network configuration for Ethernet and WiFi boards
## Build time configuration

You can configure your MQTT server credentials and network configuration before building the application. It can be done either in Arduino or in Platformio IDE thought the User_config.h file. Note that with Platformio IDE you can also set your credentials into the platformio.ini file or an *_env.ini file, here is an example with the Olimex ESP32 gateway:

Expand Down
31 changes: 1 addition & 30 deletions environments.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1623,34 +1623,6 @@ build_flags =
'-DZgatewayBT="BT"'
'-DLED_SEND_RECEIVE=2'
'-DLED_SEND_RECEIVE_ON=0'
'-DpubBLEServiceUUID=true'
'-DGateway_Name="OMG_THINGPULSE_BLE"'
'-DANEOPIX_IND_DATA_GPIO=32'
'-DANEOPIX_IND_NUM_LEDS=4'
'-DANEOPIX_INFO_LED=0'
'-DANEOPIX_SEND_RECEIVE_LED=1'
'-DANEOPIX_ERROR_LED=2'
'-DANEOPIX_BRIGHTNESS=255'
'-DRGB_INDICATORS=true'
; '-DsimplePublishing=true'
custom_description = BLE Gateway using Wifi
custom_hardware = ThingPulse gateway single ESP32

[env:thingpulse-espgateway-ethernet]
platform = ${com.esp32_platform}
board = esp32dev
board_build.partitions = min_spiffs.csv
lib_deps =
${com-esp32.lib_deps}
${libraries.ble}
${libraries.adafruit_neopixel}
${libraries.decoder}
build_flags =
${com-esp32.build_flags}
'-DZgatewayBT="BT"'
'-DLED_SEND_RECEIVE=2'
'-DLED_SEND_RECEIVE_ON=0'
'-DpubBLEServiceUUID=true'
'-DGateway_Name="OMG_THINGPULSE_ETH_BLE"'
'-DESP32_ETHERNET=true'
'-DETH_PHY_TYPE=ETH_PHY_LAN8720'
Expand All @@ -1667,6 +1639,5 @@ build_flags =
'-DANEOPIX_BRIGHTNESS=255'
'-DRGB_INDICATORS=true'
; '-DsimplePublishing=true'
custom_description = BLE Gateway using ethernet, requires PIO configuration
custom_description = BLE Gateway using ethernet or wifi with external antenna
custom_hardware = ThingPulse gateway single ESP32

5 changes: 2 additions & 3 deletions main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ const byte mac[] = {0xDE, 0xED, 0xBA, 0xFE, 0x54, 0x95}; //W5100 ethernet shield

/*-------------DEFINE YOUR ADVANCED NETWORK PARAMETERS BELOW----------------*/
//#define MDNS_SD //uncomment if you want to use mDNS for discovering automatically your IP server, please note that mDNS with ESP32 can cause the BLE to not work
#define maxConnectionRetry 10 //maximum MQTT connection attempts before going to wifimanager setup if never connected once
#define maxConnectionRetryWifi 5 //maximum Wifi connection attempts with existing credential at start (used to bypass ESP32 issue on wifi connect)
#define maxRetryWatchDog 11 //maximum Wifi or MQTT re-connection attempts before restarting
#define maxConnectionRetryNetwork 5 //maximum Wifi connection attempts with existing credential at start (used to bypass ESP32 issue on wifi connect)
#define maxRetryWatchDog 11 //maximum Wifi or MQTT re-connection attempts before restarting

//set minimum quality of signal so it ignores AP's under that quality
#define MinimumWifiSignalQuality 8
Expand Down
24 changes: 16 additions & 8 deletions main/ZmqttDiscovery.ino
Original file line number Diff line number Diff line change
Expand Up @@ -346,25 +346,33 @@ void createDiscovery(const char* sensor_type,

StaticJsonDocument<JSON_MSG_BUFFER> jsonDeviceBuffer;
JsonObject device = jsonDeviceBuffer.to<JsonObject>();
JsonArray identifiers = device.createNestedArray("identifiers");
JsonArray identifiers = device.createNestedArray("ids");

if (gateway_entity) {
//device representing the board
device["name"] = String(gateway_name);
# ifndef GATEWAY_MODEL
String model = "";
serializeJson(modules, model);
device["model"] = model;
device["mdl"] = model;
# else
device["model"] = GATEWAY_MODEL;
device["mdl"] = GATEWAY_MODEL;
# endif
device["manufacturer"] = GATEWAY_MANUFACTURER;
device["sw_version"] = OMG_VERSION;
device["mf"] = GATEWAY_MANUFACTURER;
if (ethConnected) {
# ifdef ESP32_ETHERNET
device["cu"] = String("http://") + String(ETH.localIP().toString()) + String("/"); //configuration_url
# endif
} else {
device["cu"] = String("http://") + String(WiFi.localIP().toString()) + String("/"); //configuration_url
}

device["sw"] = OMG_VERSION;
identifiers.add(String(getMacAddress()));
} else {
//The Connections
if (device_id[0]) {
JsonArray connections = device.createNestedArray("connections");
JsonArray connections = device.createNestedArray("cns");
JsonArray connection_mac = connections.createNestedArray();
connection_mac.add("mac");
connection_mac.add(device_id);
Expand All @@ -374,11 +382,11 @@ void createDiscovery(const char* sensor_type,
}

if (device_manufacturer[0]) {
device["manufacturer"] = device_manufacturer;
device["mf"] = device_manufacturer;
}

if (device_model[0]) {
device["model"] = device_model;
device["mdl"] = device_model;
}

// generate unique device name by adding the second half of the device_id only if device_name and device_id are different
Expand Down
Loading
Loading