Project: RFLink to MQTT using ESP8266 and arduino IDE

hmm

beware using multiple esp’s with the same firmware - you have to make their mqtt client id unique - which is why I added “test” mode as I would test on an esp first before rolling it onto the “production” esp. If you have a second esp trying to connect to mqtt with the same id, it will be refused.

is 127.0.0.1 a valid mqtt server? I assume it is from the command line on the machine your mqtt server runs on? maybe try the address you would use from external. I tried equivalent to your command line and got no response either … but the HASS config below works!

The other “feature” of the arduino code is that a “malformed” command will make it reset - hence adding the \n to the end to “correct” the package. So beware that you might be making the esp reset, then sending a “correct” command whilst it is still restoring from a reset sp it is being missed. (Maybe I should work for Microsoft or Apple with that subtle shift of blame for my poor coding to the user!)

so my HASS config for a wattsclever socket based upon the raw data collected is:

  - platform: mqtt
    name: "Watts1"
    state_topic: "RF/Eurodomest-ID=02df0d"
    command_topic: "RF/command"
    qos: 0
    payload_on: "10;Eurodomest;02d0f2;00;OFF\n"
    payload_off: "10;Eurodomest;02d0f2;03;OFF\n"

Have you ever transmitted successfully from the RFLink? did you try from their load tool to confirm transmit is working? I have an antenna on my receiver, but not on my transmitter, so sometimes range to the device to be controlled is an issue also.

I have many esp, and yes the client id is unique. 127.0.0.1 is ok my RPi, i’m using 192.168.1.10 in the ESP config.
So at this point I make the same configuration as you.

My RFLink can transmit when connected via USB, this part is OK. But I think I can’t when i’m using the TX Pin on the Arduino.
I’ve tried a minimal sketch on the Arduino to check both RX and TX Pins, and it works. So it’s strange.

I’m quite sure the problem is now TX on the Arduino, I think I will check a R44 or R45 to see if I have the same behavior.


Last news, I tried R44, R45,R46, same issue.
On the RFLink Loader, I’ve tried to send a command like 10;PING; it works.

Now I’ve tried esp-link. I can received code. When I send data I never get an answer.

So I’ve connected the MEGA to an UNO, link RX and TX between each other to be sure a 2nd time with another sketch. RX & TX are OK in both way.
RX TX Check i use

Any ideas why I’ve got this problem? On Mega 0 is RX and 1 is TX

This problem is solved, I connect I CP1202 on RX/TX and I can send data.
But I still can’t with ESP. So I put my serial between TX ESP and RX Arduino.
So if I copy paste data from serial ESP to Arduino, it’s ok.
But it doesn’t work directly…

hmm (again)

well - if you have definitely made the RFLink mega transmit successfully using usb and an uno

What about the mega not liking 3.3v logic? do you have a logic level shifter? My mega works ok without one at the moment.

Also, have you tried different pins for tx from the esp? maybe the pin you are using is not liked??

Also, this uses softwareserial library - have you checked for issues with that library with esp?

thx @phileep for all your help and your work, I finally have a working RFLink to MQTT.

I have clean flash on ESP and Arduino, re upload sketch, power the Arduino with 12v, used and ESP-12F (generic one) with 3.3v from Mega. Wirong has not changed.
I can’t say exactly why it works now, but it works and I have my first switch in HASS :wink: Next step, hass config for all my RF.

maybe check your power up sequence

I think if the arduino mega boots, reboot the esp (I use a node mcu) after the mega is up - has caused me issues in the past on recollection.

Anyway - enjoy setting up your mqtt sensors & switches!!

I’ve got a strange behavior, I dont know if it’s normal.

Everytime I send a command (and this is working), I’ve got juste after an MQTT entry “online” :

RF/status online
RF/command 10;NewKaku;0110b000;2;ON

RF/status online

as you can see in my mosquito_sub, I have a “\n”, the one I’ve put in home-assistant.
I’m losing one ping packet, so I suppose ESP is rebooting. But don’t know why because I’m using ‘\n’ as asked.

I have the same behavior with a direct publish on mqtt with ‘\n’ :

pi@rpi3-dev:~$ mosquitto_pub -h 127.0.0.1 -t RF/command -m "10;NewKaku;0110b000;2;ON
> "
pi@rpi3-dev:~$

It would seem to be my crappy arduino coding!

I will try and have a look later (at work now)

Might just need some management of the payload coming in from MQTT to ensure it has a trailing \n or \0 if you are keen to attempt yourself.

Thx, I gonna try by myself with test mode, but I’m not sure I have the knowledge to fix it. to be continued :slight_smile:

Hi @phileep,

Last News :
I’ve tried to debug without success. I have a an Exception(28) with a stack trace every time i use swSer. I change the SoftwareSerial lib with the one design for ESP : https://github.com/plerup/espsoftwareserial but i have the same problem.

So you use another library with your code ?

Will check what library I have installed.

Does your unit transmit an RF code before crashing?

Also, what pins are you connecting to on your NodeMCU? some pins are a bit special and might cause issues I think. Will confirm what I am using also tonight.

I’m using D5/D6 pin, so it must be GPIO12/14.

Yes, RF is transmit and execute by RFLink, but just after this ESP is crashing.

I’ve tried to do the same with swSer commented and no more crash, so i’m quite sure the problem is SoftwareSerial.

PS : small Fix for you about ‘\n’, it seems swSer.println is what you need to remove ‘\n’ from hass config.

Hi
I tried this project too, but replaced my 433 mhz devices with ESP8266/Sonoff instead.
I didn`t get this working when trying, but found this statement in the RFlink Hub page (Component): Due to different logic levels, a voltage level shifter is required between the 3.3V NodeMCU and 5V Arduino MEGA 2560 pins.

I cant see that phileep mentions this, but if you dont have on installed, maybe the ESP restart or maybe the voltage level shifter was reason why I could not get this working :slight_smile:

Hum, i have not this part. What is the difference between level shifter and level regulator ? I can just puta lm1117 ?

hmm. Not sure. I think lm1117 could interupt/change the signals. Maybe a electronics guy could help us.

When looking up the type I bought I found this in additional information part: The level converter is very easy to use. The board needs to be powered from the two voltages sources (high voltage and low voltage) that your system is using. High voltage (5V for example) to the ‘HV’ pin, low voltage (3.3V for example) to ‘LV’, and ground from the system to the ‘GND’ pin.

I think I found out why I didnt get it to work… I only supplied 5v and thought I could use the LV side for other stuff… :smiley:

I’ve made a level shifter for both side, but it doesn’t help.

I have continue my debug, and if I remove the wire from TX Arduino to RX ESP, it works. I can’t read data from RFLink, but activate is OK et non crash. So I suppose the problem is when RFLink say OK to the command I sent.


EDIT:

@phileep @Rune Found It !! I will propose a pull request on gitHub.
The problem is that RFLink send 20;xx;OK; when you send a command. (New in R46 ? if you dont have the problem ? )
The void parseData crash when it tries to get RFData. So if RFName == OK => return; to exit void. And ESP is running fine. I will add the fix for \n too. I hope I will get time this WeekEnd to propose it.

1 Like

Did you end using the level shifter?

It works with and without, so i have removed it

1 Like

Not using a level shifter is a slight risk.

However it is only on the communications in to the ESP8266, and the NODEMCU units seem tolerant, especially to such short bursts.

If you want to be sure, cheapest is a voltage divider on the TX from the MEGA as that is 5v logic. google voltage divider - you only need 2 resistors of different ratings to get the voltage down to the proper 3.3v range for the ESP.

The proof you don’t need on is that all the inward signals have been working fine. ie we can get data from the RFLink mega without the shifter.

Great work @Minims.

Will await your PR - let me know if you want me to add it by hand, although you deserve the credit in the reopo!

Some time ago the CEO of Espressif apparently tweeted that the ESP’s can handle 5V no issues.

:smiley:

1 Like

@phileep PR done, I have list my changes in the commit comment. I hope it will help :-).

No crash since I’ve applied the fix. I now use a generic ESP-12F instead of my node MCU. I use the 3.3v power of the MEGA and it seems working great.

About level shifter, I 've had a voltage divider with 1k/2k resistors just for security and because it’s not the Node MCU version.

1 Like