My Arduino UNO is up and running, but no mqtt messages

Hi All,

I’ve just started with OpenMQTTGateway and need help resolving some issues.

I use Arduino UNO with Ethernet shield and receiver (RXB6-like)/transmitter (WL102) attached, and my goal is to build a RF gateway for my 433 MHz devices to communicate with Home Assistant (on RPi3). I used these receiver/transmitter pair with Arduino Mega/RFLink and they all worked fine.

I managed to upload a project into UNO and Serial Monitor shows the following:

Simple ethernet config
OpenMQTTGateway ip:
192.168.0.37
Ethernet ok
1883
Connecting to MQTT by IP adress
192.168.0.34
RF_EMITTER_PIN
4
RF_RECEIVER_PIN
1
ZgatewayRF setup done
MQTT_MAX_PACKET_SIZE
256
Setup OpenMQTTGateway end
MQTT connection…
Connected to broker
Subscription OK to the subjects

For some reason it uses pin D1, not D3.
In the mqtt broker’s log I can see only its availability status:
home/OpenMQTTGateway/LWT online
home/OpenMQTTGateway/version 0.9beta

And apparently every time Arduino receives a 433 MHz signal it crashes because I immediately see in mqtt log:
home/OpenMQTTGateway/LWT offline

and in Serial Monitor:
MQTT connection…
failure_number
1
failed, rc=
-2
try again in 5s
MQTT connection…
failure_number
2
failed, rc=
-2
try again in 5s
MQTT connection…
failure_number
3

and it goes forever until I press Reset button on it.

Currently I have only a receiver with its data pin connected to D3 pin of the shield (4th from the nearest corner) as described here. If I connect it to D1 (2nd pin from the nearest corner), the Arduino doesn’t crash when it receives a signal, but I can see no mqtt messages in the mqtt log.

So how can I debug it and make the thing work properly?

Hi,

Could you give us the traces given by your compilation?

What is it? I’ve got only this when I select Verify/Compile:
Archiving built core (caching) in: /var/folders/47/y8hjsn9s5fb21gdtfj8bpq740000gn/T/arduino_cache_304831/core/core_arduino_avr_uno_97af79b2ac9aebec92d0dd9b1f2ab947.a
lto1: note: array types have different bounds
Sketch uses 29698 bytes (92%) of program storage space. Maximum is 32256 bytes.
Global variables use 1679 bytes (81%) of dynamic memory, leaving 369 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.

Try maybe to change mqtt max packet size to 128 in pubsubclient.h

In /library/PubSubClient/src/pubsubclient.h? I can see there only this:
#ifndef MQTT_MAX_PACKET_SIZE
#define MQTT_MAX_PACKET_SIZE 128
#endif

It’s set to 256 in .ino file. Just changed it to 128, compiled and uploaded, got this:
Archiving built core (caching) in: /var/folders/47/y8hjsn9s5fb21gdtfj8bpq740000gn/T/arduino_cache_438800/core/core_arduino_avr_uno_97af79b2ac9aebec92d0dd9b1f2ab947.a
Sketch uses 29698 bytes (92%) of program storage space. Maximum is 32256 bytes.
Global variables use 1551 bytes (75%) of dynamic memory, leaving 497 bytes for local variables. Maximum is 2048 bytes.
Low memory available, stability problems may occur.

And it changes nothing. I can see voltage changing on the data pin when I disconnect it from Arduino and emit a signal, but still no messages in mqtt log.
The first question is why it says RF_RECEIVER_PIN 1 - probably that’s the source of issues?

Flashed my Sonoff RF Bridge with the current OpenMQTTGateway and followed the instructions.
All I can see when subscribing to the # topic is:
home/OpenMQTTGateway/LWT online
home/OpenMQTTGateway/version 0.9beta
home/OpenMQTTGateway/SYStoMQTT {“uptime”:120,“freeMem”:44872,“rssi”:-47,“SSID”:“Level2”,“modules”:“SRFB”}

It does not catch any RF signals at all. Looks like a software error/lack of configuration info to me as behaves identically on different types of hardware.

p.s I did not configure any WiFi options like AP name/password, but it seems to connect to it, how?

Please open a different thread

We should try to avoid this message: [quote=“AhmadK, post:5, topic:221”]
Low memory available, stability problems may occur.
[/quote]

Could you try on your arduino uno v0.9beta ?

As you can see in my initial post, I uploaded 0.0beta into my Arduino UNO.
Don’t know how to avoid that Low memory warning though…

Yes sorry,

Here is some other tips

Could you post your user_config.h please without the credentials?

Well, I decreased the MQTT packet size to 128 and the warnings gone.
However, despite me commenting #define IR_USE_TIMER2 and uncommenting #define IR_USE_TIMER1 in /libraries/Adruino-IRremote/broaddefs.h (lines 144-145) it still says in the serial monitor:
OpenMQTTGateway ip:
192.168.0.37
Ethernet ok
1883
Connecting to MQTT by IP adress
192.168.0.34
RF_EMITTER_PIN
4
RF_RECEIVER_PIN
1

And I can see only its status messages in mqtt log

Here is the part I have changed:

#define OMG_VERSION “0.8.1”

/-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------/
//MQTT Parameters definition
//#define mqtt_server_name “www.mqtt_broker.com” // instead of defining the server by its IP you can define it by its name, uncomment this line and set the correct MQTT server host name
char mqtt_user[20] = “mqtt”; // not compulsory only if your broker needs authentication
char mqtt_pass[20] = “xxxxx”; // not compulsory only if your broker needs authentication
char mqtt_server[40] = “192.168.0.34”;
char mqtt_port[6] = “1883”;

#define Gateway_Name “OpenMQTTGateway”
#define Base_Topic “home/”
#define version_Topic Base_Topic Gateway_Name “/version”
#define will_Topic Base_Topic Gateway_Name “/LWT”
#define will_QoS 0
#define will_Retain true
#define will_Message “Offline”
#define Gateway_AnnouncementMsg “Online”

/-------------DEFINE YOUR NETWORK PARAMETERS BELOW----------------/

//#define ESPWifiManualSetup true //uncomment you don’t want to use wifimanager for your credential settings on ESP
#define WifiManager_password “your_password”
//#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 cleanFS true //uncomment if you want to clean the ESP memory and reenter your credentials
#define maxMQTTretry 4 //maximum MQTT connection attempts before going to wifi setup

//set minimum quality of signal so it ignores AP’s under that quality
#define MinimumWifiSignalQuality 8

// Update these with values suitable for your network.
#if defined(ESP32) || defined(ESPWifiManualSetup) // for nodemcu, weemos and esp8266
#define wifi_ssid “wifi ssid”
#define wifi_password “wifi password”
#else // for arduino + W5100
const byte mac[] = { 0x60, 0x01, 0x94, 0x69, 0x38, 0xC1 }; //W5100 ethernet shield mac adress
#endif

const byte ip[] = { 192, 168, 0, 37 }; //ip adress
const byte gateway[] = { 0, 0, 0, 0 }; //ip adress, if first value is different from 0 advanced config network will be used and you should fill gateway & dns
const byte Dns[] = { 0, 0, 0, 0 }; //ip adress, if first value is different from 0 advanced config network will be used and you should fill gateway & dns
const byte subnet[] = { 255, 255, 255, 0 }; //ip adress

/-------------DEFINE YOUR OTA PARAMETERS BELOW----------------/
#define ota_hostname Gateway_Name
#define ota_password “OTAPASSWORD”
#define ota_port 8266

/-------------DEFINE PINs FOR STATUS LEDs----------------/
#define led_receive 40
#define led_send 42
#define led_error 44

// VCC ------------D|-----------////\ ----------------- Arduino PIN
// LED Resistor 270-510R

/-------------DEFINE THE MODULES YOU WANT BELOW----------------/
//Addons and module management, comment the Z line

#define ZgatewayRF “RF” //ESP8266, Arduino, ESP32
//#define ZgatewayRF315 “RF315” //ESP8266, Arduino, ESP32
//#define ZgatewayIR “IR” //ESP8266, Arduino, Sonoff RF Bridge
//#define ZgatewayBT “BT” //ESP8266, Arduino, ESP32
//#define ZgatewayRF2 “RF2” //ESP8266, Arduino, ESP32
//#define ZgatewaySRFB “SRFB” // Sonoff RF Bridge
//#define Zgateway2G “2G” //ESP8266, Arduino, ESP32
//#define ZactuatorONOFF “ONOFF” //ESP8266, Arduino, ESP32, Sonoff RF Bridge
//#define ZsensorINA226 “INA226” //ESP8266, Arduino, ESP32
//#define ZsensorHCSR501 “HCSR501” //ESP8266, Arduino, ESP32, Sonoff RF Bridge
//#define ZsensorADC “ADC” //ESP8266, Arduino, ESP32
//#define ZsensorBH1750 “BH1750” //ESP8266, Arduino, ESP32
//#define ZsensorTSL2561 “TSL2561” //ESP8266, Arduino, ESP32
//#define ZsensorBME280 “BME280” //ESP8266, Arduino, ESP32
//#define ZsensorDHT “DHT” //ESP8266, Arduino, ESP32, Sonoff RF Bridge
//#define ZgatewayRFM69 “RFM69” //ESP8266, Arduino, ESP32

ok and now we have a clean install could you post a picture of your setup and point the kind of remote control you are using for your tests

Here is a picture of my setup.
As a source of RF signal I use D026 door sensor (Kerui) and a Sonoff PIR2.

I tried to select Arduino/Genuino UNO and Arduino Ethernet - what is suitable in my case (UNO+Ethernet shield)?

Did you have a look to this file?

D3 = 1 is ok, you can also try with D2 = 0

Verify also that your receiver has voltage on its pins.

Well, I saw this file, but followed this guide, and they do not match if you look at the picture

I’m still not sure what do these Dx mean, and what’s D3 = 1 etc.

My receive has 4.65V on its GNG-+5V, and I can see fluctuation of voltage (between 0 and 1.9v) on the data pin when it’s disconnected and I emit a RF signal.
But if I connect it to the pin 0 (RX), it’s constantly 4.46V and no sign of mqtt messages.

D3 is the name of the pin, 1 is the GPIO number = the number that you should set on config_RF.h

At final you should try to connect the data pin to D3 and put
RF_RECEIVER_PIN 1

or to D2 and put
RF_RECEIVER_PIN 0

The data pin of your receiver should be connected to D3 or D2 not RX

ok, thanks.
I managed to make it work, with most of the generic settings - had only do decrease MQTT_MAX_PACKET_SIZE to 256

The only question left is why it could not connect to the mqtt server when I plug the power in?
It would keep blinking green LED on the Ethernet shield until I press the Reset button on the shield - then it connects quickly.
I don’t think it is supposed to be like that, isn’t it?

Do you have something connected on TX or RX pin of the board?

You can try also to go down to 128 (could you post the result of your build from arduino IDE)?