Comments (23)
Yey ! congrats Petzi0815!!
from hcpbridge.
I had the same issue. I had to use UART 1 (pin 17&16) because for some reason UART 0 didn't work. (I think something with shared usb)
from hcpbridge.
Changed the code to
#define RS485 Serial2
[...]
#define RXD2 16
#define TXD2 17
RS485.begin(57600,SERIAL_8E1,RXD2,TXD2);
...and switched soldering to GPIO16 / GPIO17 as well. Still the same. (Also tried to reverse 16/17 to 17/16) Bus scan in menu 37 fails with "0" and devices powers off. any ideas whats wrong or how i could even try to debug something?
from hcpbridge.
Did you solder the 120Ohm resistor between A and B for bus termination?
Do you see the LEDs flashing on the rs485 module while the bus scan?
from hcpbridge.
Hi all --- I have had the same problem as petzi0815 - has anyone come up with a solution please?
from hcpbridge.
Following on from my last post - in response to MCLW - I do have the 120 ohn resistor in place but there are no LEDs flashing on the RS485 module during the bus scan ---- I have triple checked the wiring and even replaced the module but no change
from hcpbridge.
An other follow up - I also checked the E4 bus with an oscilloscope to check a bus scan was definitely happening on Menu 37 / option 1 and signals were definitely being sent on A and B. So clearly the RS485 adapter is not responding.
Another thing I noticed is that the TX0 and RX0 pins on the ESP32 are at a constant 3.3v when the program is running .... TX2 and RX2 are at 0v ---- is it normal that TX0 and RX0 are at 3.3v??
from hcpbridge.
I can also confirm that the resistor was soldered. As mentioned earlier i also used the other pins as the default UART0 is depreceated - but also with no result. I would be also very happy for any further suggestions
from hcpbridge.
Just tried to use the SWAPUART variable (by uncommenting the //#define SWAPUART) in main - which is used to trigger a serial.swap() in the setup() routine, but it would not recompile
from hcpbridge.
Do you have TX->TX and RX->RX between esp and rs485? (not TX->RX)
from hcpbridge.
Do you connect the Rs485 Board to 3,3V or 5V? Some Boards don't work with 3,3V. Connect the board to 5V instead.
from hcpbridge.
Thanks Handy Harry --- Hi - I have TX->TX and RX->RX.
Thanks MCLW --- Looking at the RS485 board, the supply terminal does say VCC, not 3.3v --- so could be it needs 5V --- will double check the specs and re-try tomorrow
from hcpbridge.
Just checked specs - the RS485 board is apparently compatible with 3.3V and 5.0V power supply and compatible with 3.3V and 5.0V signal - however I will try with 5.0V tomorrow
from hcpbridge.
Handy-Harry --- what code did you use to change the pins to 17 & 16 please?
from hcpbridge.
I will look tomorrow. My project is on hold. First I have to make a better WiFi signal at my gates
from hcpbridge.
Thanks Handy-Harry.
I'm actually looking to possibly use an ethernet connection - so starting to play with the Olimex ESP32-PoE board - got it working over wifi, now need to add the Ethernet code..... after that I will look to add MQTT as well.... fingers crossed.
from hcpbridge.
Check out my fork, if you look for an easy way to implement mqtt. I use ArduinoHA for full mqtt and HomeAssistant support.
HCPBridgeHomeassitant
from hcpbridge.
Success!!! Thanks for help guys -- changing the IO to pins 16/17 worked for me:
#define RS485 Serial2 // cuse serial2 - note also RS485.begin is changed in setup
#define PIN_TXD 17 // UART 2 TXT - G17
#define PIN_RXD 16 // UART 2 RXD - G16
in setup() :
RS485.begin(57600,SERIAL_8E1,PIN_RXD,PIN_TXD); // remap to pins 16/17
I did not need to change the supply to the RS485 adapter to 5.0v - worked fine on 3.3V
I also added code to fix the IP address
I am going to try to implement on an Olimex ESP32- gateway to give me ethernet connection instead of wifi --- will let you know if successful
Thanks MCLW for the MQTT work - will also use mqtt, although may just use the HTTP calls through node-red and convert there to MQTT first.
I'm sure all of you know about Node-Red, but if not check it out - its an incredible tool (although I am biased being an ~IBMer as I know the guys who wrote that and ~MQTT !!)
Cheers,
from hcpbridge.
Hey @Ramwells , congrats it's working. Could you please upload / dump your .cpp file with the whole source code ? Did you anything in addition to my mentioned code changes ?
So you also soldered to 16/17 instead of the tutorial version and changed the code and it's working for you? It does not for me unfortunately so you please dump your main.cpp file and specify what can of HW changes you did ?
from hcpbridge.
... ok. i have no clue why but i was able to fix it myself. maybe i did not compile properly. i also used your bit of code. so in summary. changing the code to the following and changing the wiring to pins 16,17 instead of the tutorial pins worked for me as well. 3,3 v was okay as well.
#define RS485 Serial2
[..]
#define PIN_TXD 17 // UART 2 TXT - G17
#define PIN_RXD 16 // UART 2 RXD - G16
RS485.begin(57600,SERIAL_8E1,PIN_RXD,PIN_TXD); // remap to pins 16/17
from hcpbridge.
Hi - I did move the I/O on the ESP32 to pins 16 & 17 and it worked -- as noted by Handy Harry you need to connect TX-TX and RX-RX, so for the code below I connected TX from the RS485 board to GPIO pin 17 on the ESP32 and RX to GPIO pin 16.
Don't forget the 120 ohm resistor across the A+ & B- terminals of the RS485 board.
Once I did this and re-started the HCP bus through menu 37 option 1 the RS485 board TX/RX lights started flashing and the lifter indicated there was 1 device on the bus.
The only file I changed was the main.cpp:
I also commented out the #define USERELAY, and fixed the IP address as follows:
IPAddress local_IP(192, 168, 1, 150); // Set your Static IP address
IPAddress gateway(192, 168, 1, 1); // Set your Gateway IP address
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
String hostname = "ESP32Jim1";
here is main.cpp in full:-
#include <Arduino.h>
#include <AsyncElegantOTA.h>
#include <ESPAsyncWebServer.h>
#include "AsyncJson.h"
#include "ArduinoJson.h"
#include "hciemulator.h"
//#include "index_html.h"
#include "../../WebUI/index_html.h"
/* create this file and add your wlan credentials
const char* ssid = "MyWLANSID";
const char* password = "MYPASSWORD";
*/
#include "../../../private/credentials.h"
// switch relay sync to the lamp
// e.g. the Wifi Relay Board U4648
//#define USERELAY
// use alternative uart pins
//#define SWAPUART
//#define RS485 Serial //original code
#define RS485 Serial2 // changed by JE to use serial2 - note also Serial begin is changed in setup
//Added by JE to use UART2 via pins 16 and 17
#define PIN_TXD 17 // UART 2 TXT - G17
#define PIN_RXD 16 // UART 2 RXD - G16
// Relay Board parameters
#define ESP8266_GPIO2 2 // Blue LED.
#define ESP8266_GPIO4 4 // Relay control.
#define ESP8266_GPIO5 5 // Optocoupler input.
#define LED_PIN ESP8266_GPIO2
// Hörmann HCP2 based on modbus rtu @57.6kB 8E1
HCIEmulator emulator(&RS485);
// webserver on port 80
AsyncWebServer server(80);
// called by ESPAsyncTCP-esphome:SyncClient.cpp (see patch) instead of delay to avoid connection breaks
void DelayHandler(void){
emulator.poll();
}
// switch GPIO4 und GPIO2 sync to the lamp
void onStatusChanged(const SHCIState& state){
//see https://ucexperiment.wordpress.com/2016/12/18/yunshan-esp8266-250v-15a-acdc-network-wifi-relay-module/
//Setting GPIO4 high, causes the relay to close the NO contact with
if(state.valid){
digitalWrite( ESP8266_GPIO4, state.lampOn );
digitalWrite(LED_PIN, state.lampOn);
}else
{
digitalWrite( ESP8266_GPIO4, false );
digitalWrite(LED_PIN, false);
}
}
// toggle lamp to expected state
void switchLamp(bool on){
bool toggle = (on && !emulator.getState().lampOn) || (!on && emulator.getState().lampOn);
if(toggle){
emulator.toggleLamp();
}
}
volatile unsigned long lastCall = 0;
volatile unsigned long maxPeriod = 0;
void modBusPolling( void * parameter) {
while(true){
if(lastCall>0){
maxPeriod = _max(micros()-lastCall,maxPeriod);
}
lastCall=micros();
emulator.poll();
vTaskDelay(1);
}
vTaskDelete(NULL);
}
TaskHandle_t modBusTask;
//added by JE - set IP parameters and define hostname
IPAddress local_IP(192, 168, 1, 150); // Set your Static IP address
IPAddress gateway(192, 168, 1, 1); // Set your Gateway IP address
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8); //optional
IPAddress secondaryDNS(8, 8, 4, 4); //optional
String hostname = "ESP32Jim1";
// setup mcu
void setup(){
//setup modbus
//RS485.begin(57600,SERIAL_8E1); //original code
RS485.begin(57600,SERIAL_8E1,PIN_RXD,PIN_TXD); // code by JE to map pin
#ifdef SWAPUART
RS485.swap();
#endif
xTaskCreatePinnedToCore(
modBusPolling, /* Function to implement the task /
"ModBusTask", / Name of the task /
10000, / Stack size in words /
NULL, / Task input parameter /
//1, / Priority of the task /
configMAX_PRIORITIES -1,
&modBusTask, / Task handle. /
1); / Core where the task should run */
//setup wifi
// Configures static IP address & hostname - added by JE
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");
}
WiFi.setHostname(hostname.c_str()); //define hostname
// end of block added by JE
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
WiFi.setAutoReconnect(true);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
}
// setup http server
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
AsyncWebServerResponse *response = request->beginResponse_P( 200, "text/html", index_html,sizeof(index_html));
response->addHeader("Content-Encoding","deflate");
request->send(response);
});
server.on("/status", HTTP_GET, [](AsyncWebServerRequest *request){
const SHCIState& doorstate = emulator.getState();
AsyncResponseStream *response = request->beginResponseStream("application/json");
DynamicJsonDocument root(1024);
root["valid"] = doorstate.valid;
root["doorstate"] = doorstate.doorState;
root["doorposition"] = doorstate.doorCurrentPosition;
root["doortarget"] = doorstate.doorTargetPosition;
root["lamp"] = doorstate.lampOn;
root["debug"] = doorstate.reserved;
root["lastresponse"] = emulator.getMessageAge()/1000;
root["looptime"] = maxPeriod;
lastCall = maxPeriod = 0;
serializeJson(root,*response);
request->send(response);
});
server.on("/command", HTTP_GET, [] (AsyncWebServerRequest *request) {
if (request->hasParam("action")) {
int actionid = request->getParam("action")->value().toInt();
switch (actionid){
case 0:
emulator.closeDoor();
break;
case 1:
emulator.openDoor();
break;
case 2:
emulator.stopDoor();
break;
case 3:
emulator.ventilationPosition();
break;
case 4:
emulator.openDoorHalf();
break;
case 5:
emulator.toggleLamp();
break;
default:
break;
}
}
request->send(200, "text/plain", "OK");
});
server.on("/sysinfo", HTTP_GET, [] (AsyncWebServerRequest *request) {
AsyncResponseStream *response = request->beginResponseStream("application/json");
DynamicJsonDocument root(1024);
root["freemem"] = ESP.getFreeHeap();
root["hostname"] = WiFi.getHostname();
root["ip"] = WiFi.localIP().toString();
root["ssid"] = String(ssid);
root["wifistatus"] = WiFi.status();
root["resetreason"] =esp_reset_reason();
serializeJson(root,*response);
request->send(response);
});
AsyncElegantOTA.begin(&server);
server.begin();
//setup relay board
#ifdef USERELAY
pinMode( ESP8266_GPIO4, OUTPUT ); // Relay control pin.
pinMode( ESP8266_GPIO5, INPUT_PULLUP ); // Input pin.
pinMode( LED_PIN, OUTPUT ); // ESP8266 module blue L
digitalWrite( ESP8266_GPIO4, 0 );
digitalWrite(LED_PIN,0);
emulator.onStatusChanged(onStatusChanged);
#endif
}
// mainloop
void loop(){
AsyncElegantOTA.loop();
}
from hcpbridge.
I'm happy you guys figured it out. For me it's some time ago since I was doing this project, so all was out of my head.
I'm very interested in the MQTT HA version. Also the wired version would be ideal for me. I have the WT32-ETH01 ESP32 in a ESPHOME setup (not for hormann) in my HA. This works perfect
from hcpbridge.
Hi - just FYI I have implemented a version using the Olimex ESP32 Gateway board which provides ethernet connection (instead of wifi). The serial pin assignments are slightly different as GPIO17 is used by the Ethernet function - so I re-mapped the TX of Serial2 to GPIO4 which worked. I will possibly next replace the web interface with MQTT and route through Node-Red to HA.
from hcpbridge.
Related Issues (20)
- 2 Garagedoors HOT 4
- Promatic 4 flashing red HOT 7
- PCB for Hörmann ProMatic Serie 4 HOT 4
- Using this project with a plain MAX485 breakoutboard HOT 3
- reset reason HOT 3
- Zwischenstatus? HOT 2
- Readme
- Frage: habt ihr eine kabelempfehlung HOT 2
- SoftwareSerial.cpp HOT 11
- Frage: welcher ESP32? HOT 3
- Upload scheiter
- Error 07 Communication error HOT 2
- external bus terminator HOT 1
- Idea: PCB with adapter for DHT22, BME280
- RS485 Protocol HOT 3
- Explain how to program the esp32 HOT 1
- Zu wenig Volt am Bus? HOT 53
- Lampenstatus im WebUI bei manuellem Schalten nicht korrekt HOT 5
- MQTT compatible? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hcpbridge.