Skip to content

Commit

Permalink
Merge pull request #99 from Gifford47/development
Browse files Browse the repository at this point in the history
Merged dev into Master
  • Loading branch information
Gifford47 authored Dec 23, 2024
2 parents ba257c7 + 7e44f74 commit a3761a6
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 50 deletions.
34 changes: 27 additions & 7 deletions HCPBridgeESP32/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[platformio]
;set your env you want to build default esp32 without any sensor. Comment line to build all environments.
;list separeted by , to build selected evns.
default_envs = esp32, esp32_BME280_HCSR04, m5stack-stamps3, HCP_Giffordv1a, HCP_Giffordv1b
default_envs = esp32, esp32_BME280_HCSR04, m5stack-stamps3, HCP_Giffordv1a, HCP_Giffordv1b, HCP_Giffordv2a, HCP_Giffordv2b

[common]
dht22libs =
Expand All @@ -22,7 +22,7 @@ ds18x20libs =
milesburton/DallasTemperature

[env]
platform = espressif32@6.5.0
platform = espressif32@6.9.0
board = nodemcu-32s
framework = arduino
board_build.f_cpu = 240000000L
Expand All @@ -31,12 +31,13 @@ board_build.flash_mode = qio
monitor_speed = 9600
monitor_filters = esp32_exception_decoder
lib_ldf_mode = deep+
lib_compat_mode = strict
lib_deps =
mathieucarbou/Async TCP @ ^3.1.4
mathieucarbou/AsyncTCP
heman/AsyncMqttClient-esphome@^2.1.0
bblanchon/ArduinoJson
plerup/EspSoftwareSerial
ayushsharma82/ElegantOTA@^3.1.5
ayushsharma82/ElegantOTA
paulstoffregen/OneWire
emelianov/modbus-esp8266
https://github.com/dok-net/ghostl ; << Fix missing circular_queue.h
Expand All @@ -49,7 +50,6 @@ build_flags=-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
; -D DEBUG

[env:esp32]
lib_compat_mode = strict

[env:esp32_DS18X20]
lib_deps = ${env:esp32.lib_deps} ${common.ds18x20libs}
Expand Down Expand Up @@ -121,7 +121,27 @@ extends = env:m5stack-stamps3_BME280
build_flags = ${env:m5stack-stamps3_BME280.build_flags} -D USE_HCSR04

[env:HCP_Giffordv1a]
build_flags = ${env:esp32.build_flags} -D SENSORS -D USE_HCSR04 -D USE_HCSR501 -D USE_BME
build_flags = ${env:esp32.build_flags} -D SENSORS -D USE_HCSR501 -D USE_BME

[env:HCP_Giffordv1b]
build_flags = ${env:esp32.build_flags} -D SENSORS -D USE_HCSR501 -D USE_BME
extends = env:HCP_Giffordv1a
build_flags = ${env:HCP_Giffordv1a.build_flags} -D USE_HCSR04

[env:HCP_Giffordv2a]
board = esp32-s3-devkitc-1 # https://docs.platformio.org/en/latest/frameworks/espidf.html#boards
platform = espressif32 @ 6.9.0
framework = arduino
#board_build.f_flash = 40000000L
board_build.arduino.memory_type = qio_qspi
board_build.flash_mode = qio
board_build.psram_type = qio
board_upload.flash_size = 4MB
board_upload.maximum_size = 4194304
board_build.partitions = default.csv # https://docs.platformio.org/en/latest/platforms/espressif32.html#partition-tables
board_build.extra_flags =
-DBOARD_HAS_PSRAM
build_flags = ${env:esp32.build_flags} -D HCP_Giffordv2 -D SENSORS -D USE_HCSR501 -D USE_BME

[env:HCP_Giffordv2b]
extends = env:HCP_Giffordv2a
build_flags = ${env:HCP_Giffordv2a.build_flags} -D USE_HCSR04
45 changes: 36 additions & 9 deletions HCPBridgeESP32/src/configuration.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#ifndef CONFIGURATION_H_
#define CONFIGURATION_H_
// WIFI Hostname

// Please change on every new firmware builds!
const char *HA_VERSION = "0.0.7.2";

// WIFI Hostname
const char HOSTNAME[] = "HCPBRIDGE";

// Station -> set AP_ACTIF to false if you wanna use password from config file
Expand Down Expand Up @@ -67,13 +70,23 @@
#define oneWireBus 4 //GPIO where the DS18B20 is connected to

// NOTICE: Breadboards should have 2k2 or 3k3 PullUp resistor between SCL and SDA! If not: interferences
//BME280
#define I2C_SDA 21
#define I2C_SCL 22
//BME280
#ifdef HCP_Giffordv2
#define I2C_SDA 21
#define I2C_SCL 33
#else
#define I2C_SDA 21
#define I2C_SCL 22
#endif

//HC-SR04
#define SR04_TRIGPIN 5
#define SR04_ECHOPIN 18
//HC-SR04
#ifdef HCP_Giffordv2
#define SR04_TRIGPIN 5
#define SR04_ECHOPIN 48
#else
#define SR04_TRIGPIN 5
#define SR04_ECHOPIN 18
#endif
#define SR04_MAXDISTANCECM 150
#define SOUND_SPEED 0.034 //define sound speed in cm/uS

Expand All @@ -82,7 +95,22 @@
#define DHTTYPE DHT22

//HC-SR501
#define SR501PIN 23
#ifdef HCP_Giffordv2
#define SR501PIN 23
#else
#define SR501PIN 34
#endif

//digital in- and outputs
#ifdef HCP_Giffordv2
#define LED1 13
#define INPUT1 12
#define INPUT2 14
#define OUTPUT1 37
#define OUTPUT2 35
#define MQ2_ANALOG 36
#define MQ2_DIG 15
#endif

// MQTT strings
#define HA_DISCOVERY_BIN_SENSOR "homeassistant/binary_sensor/%s/%s/config"
Expand Down Expand Up @@ -126,6 +154,5 @@
const char *HA_ONLINE = "online";
const char *HA_OFFLINE = "offline";
#endif
const char *HA_VERSION = "0.0.7.1";

#endif
54 changes: 27 additions & 27 deletions HCPBridgeESP32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ AsyncWebServer server(80);
float bme_last_hum = -99.99;
float bme_pres = -99.99;
float bme_last_pres = -99.99;
int i2c_onoffpin = 0;
int i2c_sdapin = 0;
int i2c_sclpin = 0;
#endif
Expand Down Expand Up @@ -178,6 +177,7 @@ void setuptMqttStrings(){
strcpy(mqttStrings.sensor_topic, mqttStrings.st_sensor_topic.c_str());
strcpy(mqttStrings.debug_topic, mqttStrings.st_debug_topic.c_str());
}

void IRAM_ATTR reset_button_change(){
if (digitalRead(0) == 0)
{
Expand All @@ -199,7 +199,7 @@ void resetPreferences()
{
xTimerStop(resetTimer, 0);
Serial.println("Resetting config...");
prefHandler.resetPreferences();
//prefHandler.resetPreferences();
}

void switchLamp(bool on){
Expand Down Expand Up @@ -753,31 +753,20 @@ void SensorCheck(void *parameter){
}
#endif
#ifdef USE_BME
if (digitalRead(i2c_onoffpin) == LOW) {
digitalWrite(i2c_onoffpin, HIGH); // activate sensor
sleep(10);
I2CBME.begin(i2c_sdapin, i2c_sclpin); // https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/
bme_status = bme.begin(0x76, &I2CBME); // check sensor. adreess can be 0x76 or 0x77
}
I2CBME.begin(i2c_sdapin, i2c_sclpin); // https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/
bme_status = bme.begin(0x76, &I2CBME); // check sensor. adreess can be 0x76 or 0x77
if (!bme_status) {
bme_status = bme.begin(0x77, &I2CBME); // check sensor. address can be 0x76 or 0x77
}
if (!bme_status) {
digitalWrite(i2c_onoffpin, LOW); // deactivate sensor
}
else {
bme_temp = bme.readTemperature(); // round float
bme_hum = bme.readHumidity();
bme_pres = bme.readPressure()/100; // convert from pascal to mbar
if (bme_hum < 99.9){ // I2C hung up ...
if (abs(bme_temp-bme_last_temp) >= sensor_temp_thresh || abs(bme_hum-bme_last_hum) >= sensor_hum_thresh || abs(bme_pres-bme_last_pres) >= sensor_pres_thresh){
bme_last_temp = bme_temp;
bme_last_hum = bme_hum;
bme_last_pres = bme_pres;
new_sensor_data = true;
}
} else {
digitalWrite(i2c_onoffpin, LOW); // deactivate sensor
bme_temp = bme.readTemperature(); // round float
bme_hum = bme.readHumidity();
bme_pres = bme.readPressure()/100; // convert from pascal to mbar
if (bme_hum < 99.9){ // I2C hung up ...
if (abs(bme_temp-bme_last_temp) >= sensor_temp_thresh || abs(bme_hum-bme_last_hum) >= sensor_hum_thresh || abs(bme_pres-bme_last_pres) >= sensor_pres_thresh){
bme_last_temp = bme_temp;
bme_last_hum = bme_hum;
bme_last_pres = bme_pres;
new_sensor_data = true;
}
}
#endif
Expand Down Expand Up @@ -947,14 +936,19 @@ void setup()
}
*/

#ifdef HCP_Giffordv2
pinMode(LED1, OUTPUT); // Sets the trigPin as an Output
digitalWrite(LED1, HIGH);
#endif

// setup preferences
prefHandler.initPreferences();
localPrefs = prefHandler.getPreferences();
// setup modbus
hoermannEngine->setup(localPrefs);

//Add interrupts for Factoryreset over Boot button
pinMode(0, INPUT_PULLUP);
pinMode(0, INPUT);
attachInterrupt(digitalPinToInterrupt(0), reset_button_change, CHANGE);
resetTimer = xTimerCreate("resetTimer", pdMS_TO_TICKS(10), pdFALSE, (void*)0, reinterpret_cast<TimerCallbackFunction_t>(resetPreferences));

Expand Down Expand Up @@ -1019,7 +1013,6 @@ void setup()
#ifdef USE_BME
i2c_sdapin = localPrefs->getInt(preference_sensor_i2c_sda);
i2c_sclpin = localPrefs->getInt(preference_sensor_i2c_scl);
pinMode(i2c_onoffpin, OUTPUT);
I2CBME.begin(i2c_sdapin, i2c_sclpin); // https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/
bme_status = bme.begin(0x76, &I2CBME); // check sensor. adreess can be 0x76 or 0x77
//bme_status = bme.begin(); // check sensor. adreess can be 0x76 or 0x77
Expand Down Expand Up @@ -1099,6 +1092,9 @@ void setup()
dtostrf(dht22_temp,2,1,buf);
strcat(buf, " °C");
sensors["temp"] = buf;
dtostrf(dht22_hum,2,1,buf);
strcat(buf, " %");
sensors["hum"] = buf;
#endif
#ifdef USE_HCSR04
dtostrf(hcsr04_distanceCm,2,0,buf);
Expand Down Expand Up @@ -1213,9 +1209,13 @@ void setup()
ElegantOTA.setAuth(OTA_USERNAME, OTA_PASSWD);

server.begin();
#ifdef HCP_Giffordv2
pinMode(LED1, OUTPUT); // Sets the trigPin as an Output
digitalWrite(LED1, LOW);
#endif
}

// mainloop
void loop(){
ElegantOTA.loop();
}
}
116 changes: 116 additions & 0 deletions docs/ESPhome_getting_started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Getting started with the ESPHome version

Our boards from tynet.eu ship with the normal Arduino based Firmware that is simple to use out of the box.
Sadly this software that was developed over the past years got some minor inconveniences that are not simple to fix.
If you are one of the few people that have an issue with th software or just wan't to use ESPHome instead you can follow this guide

ESPHome uses a native Home Assistant API instead of MQTT and is simple to setup, we also porivde configuration files as well as ready to flash bin files for our boards.

## Setup ESPHome in Home Assistant

You can follow the [official guide](https://esphome.io/guides/getting_started_hassio) to install the ESPHome Add-on for Home Assistant.

The main steps are:

1. Open your Home Assitant UI
2. Go to Settings->Add-Ons->Add-on Store and search for ESPHome
3. Install and activate the ESPHome addon

## Upgrade from non ESPHome firmware

Our boards all ship with a non ESPHome based firmware, it can be upgraded really simple.

1. Ensure your board is powered over USB-C
2. Download ESPHome based firmware file: [hcpbridge.ota.bin](https://github.com/Tysonpower/HCPBridgeMqtt_tynet/raw/refs/heads/main/hcpbridge.ota.bin)
3. Connect to your board and open the OTA webui: [http://192.168.4.1/update](http://192.168.4.1/update)
4. If asked use the following credentials to login: `user: admin pass: admin`
5. Click "Select File", navigate to the downloaded ota file from step 1,

## Board Setup

### Using USB (recommended)

1. Ensure your board is connected to your PC over USB-C
2. Open [web.ESPHome.io](https://web.esphome.io), click connect, select the ESP32-S3 device from the list
3. Click the 3 point menu and select Configure Wifi, select or anter your wifi name and password
<img width="659" alt="image" src="https://github.com/user-attachments/assets/789d1c11-b7df-4c48-9421-5397f1cb5cc1">

4. After entering your wifi credentials click connect
<img width="419" alt="image" src="https://github.com/user-attachments/assets/e22cbe8f-8ec8-42d8-8ec0-0d80b87ba629">

### Using WiFi

1. Ensure your board is powered over USB-C
2. Search and connect to the wifi called `hcpbridge`
3. Open http://192.168.4.1 when connected, login is `user: admin pass: tynet.eu`
4. Connect to your wifi network over the UI
____

Now your board should be connected to your home network over wifi.

Open home Assistant, go to Devices, here the garage door should be visible under discovered devices, just click "Add".

![image](https://github.com/user-attachments/assets/278d3c7b-f70f-47df-ab5e-c5430bf2f175)


## Change preflashed config (Optional)

1. open home assistant and go to the ESPHome UI under Add-Ons
2. You should see the dicovered device, press take control. if you like, change the name
![image](https://github.com/user-attachments/assets/04714647-a317-4312-9d11-c7755bf53faf)

4. it will ask to update the device with encryption, click install, it will take a wile to build the new firmware
![image](https://github.com/user-attachments/assets/38ce6137-78ff-4f72-aea1-fe9cc9cb473d)

5. When it finished uploading you will see the following log output, if this is the case you can press close and you are done
![image](https://github.com/user-attachments/assets/21efb5b9-3eea-4ca7-b932-d811f7a52831)

In some cases you need to set your wifi credentials again afterwards like before


## Setup ESPHome in Home Assistant from scratch

1. Open ESPHome in Home Assistant
2. Connect your board only via usb to your PC
3. Click "New Device" and enter a name
<img width="409" alt="image" src="https://github.com/user-attachments/assets/c01adb14-b041-4001-88d8-c1de9aa4d283">

4. Click ESP32-S3
<img width="412" alt="image" src="https://github.com/user-attachments/assets/2f96c7cd-9611-45e3-ac7b-9eef8695aa58">

5. Copy and save the displayed encryption key and click skip
<img width="412" alt="image" src="https://github.com/user-attachments/assets/0601f882-b53e-445d-bc7c-b402f84b355b">

6. Click on the secrets button on the top right, create the following keys and enter your wifi credentials as well as the secret api key you just copied, hit save

```
wifi_ssid: "myWifi"
wifi_password: "myWifiPassword"
api_key: "myApiSecretWeCopiedAfewMinutesAgo"
web_username: "admin"
web_password: "tynet.eu"
hcp_wifi_ap_password: "tynet.eu"
```

7. Click Edit on the device card
<img width="404" alt="image" src="https://github.com/user-attachments/assets/0c3b92ee-bd92-488f-8b1d-f8b9932b61c1">

8. Copy paste the content of the ESPHome.yaml file from this repo into the editor, click save
<img width="857" alt="image" src="https://github.com/user-attachments/assets/d6283427-480f-4128-8c11-9a84b51699a7">


9. Click install, then select Manual download, wait for the firmware to be build, select factory format to get the.bin file
<img width="1070" alt="image" src="https://github.com/user-attachments/assets/bc316b5e-8e84-47a2-a0fb-bd4f69eaa117">

<img width="1070" alt="image" src="https://github.com/user-attachments/assets/efff77d5-2ae1-4152-be38-c851fb496f2b">

10. Then go to [web.ESPHome.io](https://web.esphome.io/), click connect and select your ESP from the device list, click INSTALL, select the .bin file you just downloaded and click Install.
If it doesen't work, try it multiple times
<img width="1070" alt="image" src="https://github.com/user-attachments/assets/5d1d382a-e449-4071-835c-67cbf3130ed4">

11. go back to home assistant, open settings->devices->ESPHome, here you should be able to add the device, if not try to powercycle the board
<img width="1056" alt="image" src="https://github.com/user-attachments/assets/4d591352-ec6e-4184-b109-da8ef8a03a5a">

Click done and you can now use the Device
<img width="1056" alt="image" src="https://github.com/user-attachments/assets/f918b4ef-936f-4581-8b93-9a31abca524a">

Loading

0 comments on commit a3761a6

Please sign in to comment.