Gateway sends NACK to node
-
This is the gateway code as well.
/* Name: GatewaySerialLora.ino Created: 6/6/2022 11:10:17 AM Author: mariu */ /** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2020 Sensnology AB * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * DESCRIPTION * The ArduinoGateway prints data received from sensors on the serial link. * The gateway accepts input on serial which will be sent out on radio network. * * The GW code is designed for Arduino Nano 328p / 16MHz * * Wire connections (OPTIONAL): * - Inclusion button should be connected between digital pin 3 and GND * - RX/TX/ERR leds need to be connected between +5V (anode) and digital pin 6/5/4 with resistor 270-330R in a series * * LEDs (OPTIONAL): * - To use the feature, uncomment any of the MY_DEFAULT_xx_LED_PINs * - RX (green) - blink fast on radio message received. In inclusion mode will blink fast only on presentation received * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly * - ERR (red) - fast blink on error during transmission error or receive crc error * */ // Enable debug prints to serial monitor #include <SPI.h> #define MY_DEBUG // Enable and select radio type attached //#define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 #define MY_RADIO_RFM95 //#define MY_DEBUG_VERBOSE_RFM95 #define MY_RFM95_FREQUENCY (RFM95_868MHZ) #define MY_TRANSPORT_STATE_TIMEOUT_MS (5*1000ul) #define RFM95_RETRY_TIMEOUT_MS (3000ul) #define MY_RFM95_MAX_POWER_LEVEL_DBM (1) //1mW = 0dBm 10mW = 10dBm 25mW = 14dBm 100mW = 20dBm //#define MY_RFM95_TX_POWER_DBM (13u) //#define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR45SF1288 #define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR48SF4096 #define MY_RFM95_RST_PIN (9) //#define MY_RFM95_POWER_PIN (3) //#define DEFAULT_RFM95_IRQ_PIN #define DEFAULT_RFM95_CS_PIN (10) // Enable serial gateway #define MY_GATEWAY_SERIAL // Define a lower baud rate for Arduinos running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender) #if F_CPU == 8000000L #define MY_BAUD_RATE 38400 #endif // Enable inclusion mode #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway //#define MY_INCLUSION_BUTTON_FEATURE // Inverses behavior of inclusion button (if using external pullup) //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP // 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 // Inverses the behavior of leds //#define MY_WITH_LEDS_BLINKING_INVERSE // Flash leds on rx/tx/err // Uncomment to override default HW configurations //#define MY_DEFAULT_ERR_LED_PIN 4 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 6 // Receive led pin //#define MY_DEFAULT_TX_LED_PIN 5 // the PCB, on board LED #include <MySensors.h> #include <MyConfig.h> #define SLEEP_TIME_MS (24ul*60ul*60ul*1000ul) // Sleep time between battery reports (24h, in milliseconds) #define CHILD_ID 1 // Id of the sensor child // Initialize motion message MyMessage msg(CHILD_ID, V_TRIPPED); const float VccMin = 2.8; // Minimum expected Vcc level, in Volts: Brownout at 1.8V -> 0% const float VccMax = 3.8; // Maximum expected Vcc level, in Volts: 2xAA fresh Alkaline -> 100% const float VccCorrection = 1.0; // Measured Vcc by multimeter divided by reported Vcc int BATTERY_SENSE_PIN = A6; // select the input pin for the battery sense point void setup() { // Setup locally attached sensors analogReference(INTERNAL); } void presentation() { sendSketchInfo(F("Serial Gateway"), F("1.0")); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID, S_CUSTOM, F("Gateway Battery Level")); // Present locally attached sensors } void loop() { delay(10000); // Send locally attached sensor data here uint16_t res = analogRead(A6); const uint8_t batteryPcnt = map(res, 0, 4096, 0, 100); // //const uint8_t batteryPcnt = static_cast<uint8_t>(0.5 + vcc.Read_Perc(VccMin, VccMax)); sendBatteryLevel(batteryPcnt); //sendBatteryLevel(); #ifdef MY_DEBUG float batteryV = res * 0.003363075; Serial.print("Battery Voltage: "); Serial.print(batteryV); Serial.println(" V"); Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); #endif //if (oldBatteryPcnt != batteryPcnt) { // // Power up radio after sleep // sendBatteryLevel(batteryPcnt); // oldBatteryPcnt = batteryPcnt; //} } -
-
This is very strange but could indicate where to look for similar problems. I dumped the mysensors gateway and node and programed the arduinos with the standard arduino Lora libary to establish a serial device on HA. This worked first time and I could get messages through, no problem. This means that the radios was at least working. Then I reprogramed the gateway and the node with mysensors serial GW and node options. The radios connected first time and I don't think I received a single NACK for two days now.
So I can only think that there must be some radio setup parameters that are stuck in memory or something like that.Any ideas from someone on this?
-
This is very strange but could indicate where to look for similar problems. I dumped the mysensors gateway and node and programed the arduinos with the standard arduino Lora libary to establish a serial device on HA. This worked first time and I could get messages through, no problem. This means that the radios was at least working. Then I reprogramed the gateway and the node with mysensors serial GW and node options. The radios connected first time and I don't think I received a single NACK for two days now.
So I can only think that there must be some radio setup parameters that are stuck in memory or something like that.Any ideas from someone on this?
@mariusl said in Gateway sends NACK to node:
Any ideas from someone on this?
#define MY_TRANSPORT_STATE_TIMEOUT_MS (5*1000ul)
//#define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR45SF1288
#define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR48SF4096These lines can affect. the TRANSPORT_STATE_TIMEOUT may be less than a actual message sending time. you will get constant NACK's.
-
@mariusl said in Gateway sends NACK to node:
Any ideas from someone on this?
#define MY_TRANSPORT_STATE_TIMEOUT_MS (5*1000ul)
//#define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR45SF1288
#define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR48SF4096These lines can affect. the TRANSPORT_STATE_TIMEOUT may be less than a actual message sending time. you will get constant NACK's.
@yury said in Gateway sends NACK to node:
These lines can affect. the TRANSPORT_STATE_TIMEOUT may be less than a actual message sending time. you will get constant NACK's.
I have it working fine now but I would like to make it as robust as possible. What would you suggest as a good value for the timeout?
-
@mariusl said in Gateway sends NACK to node:
good value for the timeout?
here are the delay examples in the docs
https://www.mysensors.org/apidocs/group__RFM95grp.html#ga23a30185cbd40984e65d5269983bf840for yours #define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR48SF4096
I would use #define RFM95_RETRY_TIMEOUT_MS (2000ul)
any reason for the Spread factor SF4096 ?
-
@mariusl said in Gateway sends NACK to node:
good value for the timeout?
here are the delay examples in the docs
https://www.mysensors.org/apidocs/group__RFM95grp.html#ga23a30185cbd40984e65d5269983bf840for yours #define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW125CR48SF4096
I would use #define RFM95_RETRY_TIMEOUT_MS (2000ul)
any reason for the Spread factor SF4096 ?
-
@mariusl said in Gateway sends NACK to node:
what it does
SF number is chips (chirps) needed to code each bit. SF4096 is maximum range especially in urban area, but very long delay . I tried different combinations and found below MY_RFM95_MODEM_CONFIGRUATION is pretty much good. 20 - 30% less in terms of distance and delay #define RFM95_RETRY_TIMEOUT_MS (300ul) is enoght. Much faster.
#define MY_RFM95_MODEM_CONFIGRUATION RFM95_BW_500KHZ | RFM95_CODING_RATE_4_5, RFM95_SPREADING_FACTOR_2048CPS | RFM95_RX_PAYLOAD_CRC_ON, RFM95_AGC_AUTO_ON
-
Aah ok that makes sense. My application is for rural use and I need the max distance possible. The slow response will not be a problem as the sensors don't send a lot of data at all. So maybe I will stay with the SF4096 for now but I will do some experimenting with the settings. Just to understand them a bit better.