Hi guys.
I'm using an Arduino Uno + 5100 based MQTT Gateway.
It's working great with sensors and mqtt but I have a couple if issues that may be related.
-
It is very slow to connect to the ethernet switch
-
won't send registration nor info about local sensors.
Power supply is ok, external regulated 5V + 3v3 reg for nrf. All OK's on the radio front.
Take a look at the startup log:
MCO:BGN:INIT GW,CP=RNNGA---,REL=255,VER=2.3.1
4 TSM:INIT
5 TSF:WUR:MS=0
11 TSM:INIT:TSP OK
13 TSM:INIT:GW MODE
15 TSM:READY:ID=0,PAR=0,DIS=0
17 MCO:REG:NOT NEEDED
580 GWT:TPC:IP=192.168.1.200
1583 MCO:BGN:STP
1585 MCO:BGN:INIT OK,TSP=1
1587 GWT:TPC:IP=192.168.1.200
2590 GWT:RMQ:MQTT RECONNECT
3594 TSM:READY:NWD REQ
3631 TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
3638 TSF:MSG:READ,11-11-0,s=255,c=3,t=21,pt=1,l=1,sg=0:0
3645 GWT:TPC:IP=192.168.1.200
4647 GWT:RMQ:MQTT RECONNECT
5652 TSF:MSG:READ,0-11-255,s=255,c=3,t=20,pt=0,l=0,sg=0:
5657 TSF:MSG:BC
5659 TSF:MSG:READ,2-2-0,s=255,c=3,t=21,pt=1,l=1,sg=0:0
5664 TSF:MSG:READ,0-2-255,s=255,c=3,t=20,pt=0,l=0,sg=0:
5669 TSF:MSG:BC
5671 GWT:TPC:IP=192.168.1.200
6674 GWT:RMQ:MQTT RECONNECT
7678 GWT:TPC:IP=192.168.1.200
8681 GWT:RMQ:MQTT RECONNECT
9687 GWT:TPC:IP=192.168.1.200
10690 GWT:RMQ:MQTT RECONNECT
11695 GWT:TPC:IP=192.168.1.200
12697 GWT:RMQ:MQTT RECONNECT
13702 GWT:TPC:IP=192.168.1.200
14704 GWT:RMQ:MQTT RECONNECT
15710 GWT:TPC:IP=192.168.1.200
16713 GWT:RMQ:MQTT RECONNECT
17717 GWT:TPC:IP=192.168.1.200
18720 GWT:RMQ:MQTT RECONNECT
19725 GWT:TPC:IP=192.168.1.200
20727 GWT:RMQ:MQTT RECONNECT
21733 GWT:TPC:IP=192.168.1.200
22736 GWT:RMQ:MQTT RECONNECT
23741 GWT:TPC:IP=192.168.1.200
24743 GWT:RMQ:MQTT RECONNECT
25749 GWT:TPC:IP=192.168.1.200
26752 GWT:RMQ:MQTT RECONNECT
27758 GWT:TPC:IP=192.168.1.200
28762 GWT:RMQ:MQTT RECONNECT
29767 GWT:TPC:IP=192.168.1.200
30770 GWT:RMQ:MQTT RECONNECT
30777 GWT:RMQ:MQTT CONNECTED
Only then, it starts working ok.
When in that MQTT Reconnect, it is not responding any pings. As soon as it gets the ethernet connection running, it connects to the broker at the first attempt.
It is directly connected to a Cisco switch. I tried everything, auto/auto, 10/full, 100/full. Any ethernet combo it's the same.
This is the complete sketch:
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enables and select radio type (if attached)
#define MY_RADIO_RF24
#define MY_RF24_CHANNEL 110
// modulo con amplificador, por ahi recomiendan bajarle la potencia (?)
#define MY_RF24_PA_LEVEL RF24_PA_LOW
#define MY_GATEWAY_MQTT_CLIENT
// Set this node's subscribe and publish topic prefix
#define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
// Set MQTT client id
#define MY_MQTT_CLIENT_ID "mysensors-1"
// W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
// descomentΓ³ guille
//#define MY_W5100_SPI_EN 4
// Enable Soft SPI for NRF radio (note different radio wiring is required)
// The W5100 ethernet module seems to have a hard time co-operate with
// radio on the same spi bus.
#if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
#define MY_SOFTSPI
#define MY_SOFT_SPI_SCK_PIN 14
#define MY_SOFT_SPI_MISO_PIN 16
#define MY_SOFT_SPI_MOSI_PIN 15
#endif
// When W5100 is connected we have to move CE/CSN pins for NRF radio
#ifndef MY_RF24_CE_PIN
#define MY_RF24_CE_PIN 5
#endif
#ifndef MY_RF24_CS_PIN
#define MY_RF24_CS_PIN 6
#endif
// Enable these if your MQTT broker requires username/password
//#define MY_MQTT_USER "username"
//#define MY_MQTT_PASSWORD "password"
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
#define MY_IP_ADDRESS 192,168,1,200
// If using static ip you can define Gateway and Subnet address as well
#define MY_IP_GATEWAY_ADDRESS 192,168,1,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
// MQTT broker ip address or url. Define one or the other.
//#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
#define MY_CONTROLLER_IP_ADDRESS 192, 168, 1,2
// The MQTT broker port to to open
#define MY_PORT 8884
/*
// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
//#define MY_INCLUSION_BUTTON_FEATURE
// Set inclusion mode duration (in seconds)
#define MY_INCLUSION_MODE_DURATION 60
// Digital pin used for inclusion mode button
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Flash leds on rx/tx/err
// Uncomment to override default HW configurations
//#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
//#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
//#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
*/
#include <Ethernet.h>
#include <MySensors.h>
// Temperatura
#include <SPI.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
#define ONE_WIRE_BUS 2 // Pin where dallase sensor is connected
#define MAX_ATTACHED_DS18B20 16
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
float lastTemperature[MAX_ATTACHED_DS18B20];
int numSensors=0;
// Initialize temperature message
MyMessage msg(0,V_TEMP);
//
void setup()
{
// Setup locally attached sensors
// temperatura
sensors.setWaitForConversion(false);
}
void presentation()
{
// Present locally attached sensors here
sendSketchInfo("Gateway node with temp", "1.0");
// Fetch the number of attached temperature sensors
numSensors = sensors.getDeviceCount();
present(1, S_TEMP);
}
void loop()
{
// Send locally attached sensors data here
// Fetch temperatures from Dallas sensors
sensors.requestTemperatures();
// query conversion time and sleep until conversion completed
int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
// sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
wait(conversionTime);
// Read temperatures and send them to controller
for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
// Fetch and round temperature to one decimal
float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
Serial.println(temperature);
// Only send data if temperature has changed and no error
#if COMPARE_TEMP == 1
if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
#else
if (temperature != -127.00 && temperature != 85.00) {
#endif
// Send in the new temperature
send(msg.setSensor(i).set(temperature,1));
// Save new temperatures for next compare
lastTemperature[i]=temperature;
}
}
// Estudiar un poco esto. Le pongo algo para que no estΓ© midiendo
// permanentemente
wait(1000);
}
I'm on 2.3.1
The main issue here is the failure to use local sensors, but a faster startup time would also be great.
Thanks in advance for any tip.
Guillermo