[Solved] RFM69 and RaspberryPI GW
-
Hello,
Since I wasn't been so successful with the NRF24+'s (lots of dropped packets because I'm using signing and it uses the whole frame, increasing the probability of failed transmissions) I bought a few 433MHz RFM69's and NRF2RFM69 adapters to test it.
However, I'm even behind now because I can't get them to communicate. Maybe someone could point me towards the right direction?On the Raspberry PI I re-configured the gateway with the corresponding RFM69 commands:
> ./configure --my-gateway=ethernet --my-port=5003 --my-transport=rfm69 --my-signing=software --my-signing-request-signatures --my-rfm69-frequency=433 > make > sudo make install
The signature part remains the same, as the config file remains identical.
Rebooted it and it seems its OK in the logs:
Aug 28 17:06:28 nettemp mysgw: Starting gateway... Aug 28 17:06:28 nettemp mysgw: Protocol version - 2.3.0 Aug 28 17:06:28 nettemp mysgw: MCO:BGN:INIT GW,CP=RPNGLS--,VER=2.3.0 Aug 28 17:06:28 nettemp mysgw: TSF:LRT:OK Aug 28 17:06:28 nettemp mysgw: TSM:INIT Aug 28 17:06:28 nettemp mysgw: TSF:WUR:MS=0 Aug 28 17:06:28 nettemp mysgw: TSM:INIT:TSP OK Aug 28 17:06:28 nettemp mysgw: TSM:INIT:GW MODE Aug 28 17:06:28 nettemp mysgw: TSM:READY:ID=0,PAR=0,DIS=0 Aug 28 17:06:28 nettemp mysgw: MCO:REG:NOT NEEDED Aug 28 17:06:28 nettemp mysgw: Listening for connections on 0.0.0.0:5003 Aug 28 17:06:28 nettemp mysgw: MCO:BGN:STP Aug 28 17:06:28 nettemp mysgw: MCO:BGN:INIT OK,TSP=1 Aug 28 17:07:18 nettemp mysgw: New connection from 127.0.0.1 Aug 28 17:07:18 nettemp mysgw: GWT:TSA:C=0,CONNECTED Aug 28 17:07:18 nettemp mysgw: GWT:RFC:C=0,MSG=0;0;3;0;2; Aug 28 17:07:18 nettemp mysgw: GWT:RFC:C=0,MSG=
I initially started to do tests using the slim nodes, but after some failed tries and troubleshooting I realized that it doesn't have a connection to D2 pin, which seems to be required for RFM69 for interrupt purposes, so I took a sensebender micro, which should have.
The main changes in the sensebender code were basically:
#define MY_RADIO_RFM69 // Define for using RFM69 radio #define MY_RFM69_FREQUENCY RFM69_433MHZ #define MY_RFM69_NEW_DRIVER
However, it seems they don't communicate:
__ __ ____ | \/ |_ _/ ___| ___ _ __ ___ ___ _ __ ___ | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __| | | | | |_| |___| | __/ | | \__ \ _ | | \__ \ |_| |_|\__, |____/ \___|_| |_|___/\___/|_| |___/ |___/ 2.3.0 16 MCO:BGN:INIT NODE,CP=RPNNAS--,VER=2.3.0 71 SGN:PER:OK 92 SGN:INI:BND OK 94 TSM:INIT 94 TSF:WUR:MS=0 98 TSM:INIT:TSP OK 100 TSM:INIT:STATID=50 102 TSF:SID:OK,ID=50 104 TSM:FPAR 106 SGN:SGN:NREQ=255 112 TSF:MSG:SEND,50-50-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 2121 !TSM:FPAR:NO REPLY 2123 TSM:FPAR 2125 SGN:SGN:NREQ=255 2131 TSF:MSG:SEND,50-50-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 4141 !TSM:FPAR:NO REPLY 4143 TSM:FPAR 4145 SGN:SGN:NREQ=255 4151 TSF:MSG:SEND,50-50-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 6160 !TSM:FPAR:NO REPLY 6162 TSM:FPAR 6164 SGN:SGN:NREQ=255 6170 TSF:MSG:SEND,50-50-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK: 8179 !TSM:FPAR:FAIL 8181 TSM:FAIL:CNT=1 8183 TSM:FAIL:DIS 8185 TSF:TDI:TSL
The node can't find a parent, and they are in the same room, at a 6m distance.
I've tried swapping the radios, still no luck...I double-checked the wiring and it's OK (and if it wasn't, the TSP woudn't come up, right?).
I've tried with and without the " #define MY_RFM69_NEW_DRIVER " declaration.
I'm using the latest version of MySensors Library (2.3.0) on both GW and node.I'm short on ideas for the next step. Any suggestion?
I'm posting the code just for reference (most of it commented so I could have space for debug info).
/** * 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-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/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. * ******************************* * * REVISION HISTORY * Version 1.0 - Thomas Bowman MC8rch * * DESCRIPTION * Default sensor sketch for Sensebender Micro module * Act as a temperature / humidity sensor by default. * * If A0 is held low while powering on, it will enter testmode, which verifies all on-board peripherals * * Battery voltage is as battery percentage (Internal message), and optionally as a sensor value (See defines below) * * * Version 1.3 - Thomas Bowman MC8rch * Improved transmission logic, eliminating spurious transmissions (when temperatuere / humidity fluctuates 1 up and down between measurements) * Added OTA boot mode, need to hold A1 low while applying power. (uses slightly more power as it's waiting for bootloader messages) * * Version 1.4 - Thomas Bowman MC8rch * * Corrected division in the code deciding whether to transmit or not, that resulted in generating an integer. Now it's generating floats as expected. * Simplified detection for OTA bootloader, now detecting if MY_OTA_FIRMWARE_FEATURE is defined. If this is defined sensebender automaticly waits 300mS after each transmission * Moved Battery status messages, so they are transmitted together with normal sensor updates (but only every 60th minute) * * * * MY STUFF: * NODE: Janela Norte - SALA ID: 50 * HW: SENSEBENDER MICRO * * BATT_SENSOR 199 * DOOR 30 D3 * TEMPERATURE 20 I2C * HUMIDITY 40 I2C * * * */ // Enable debug prints to serial monitor #define MY_DEBUG //#define DOOR //#define HUM //#define BAT //#define TEST_MODE //CODE FOR SIGNING************************************************ //#define MY_SIGNING_WEAK_SECURITY #define MY_SIGNING_SOFT #define MY_SIGNING_SOFT_RANDOMSEED_PIN A1 #define MY_SIGNING_REQUEST_SIGNATURES // will inform the gateway that I expect it to sign all messages to me #define MY_DEBUG_VERBOSE_SIGNING // Define a static node address, remove if you want auto address assignment #define MY_NODE_ID 50 // Child sensor ID's #define CHILD_ID_TEMP 20 #ifdef HUM #define CHILD_ID_HUM 40 #endif #ifdef DOOR #define CHILD_ID_A 30 // DOOR #endif // Uncomment the line below, to transmit battery voltage as a normal sensor value #ifdef BAT #define BATT_SENSOR 199 #endif // Enable and select radio type attached //#define MY_RADIO_NRF24 #define MY_RADIO_RFM69 // Define for using RFM69 radio #define MY_RFM69_FREQUENCY RFM69_433MHZ #define MY_RFM69_NEW_DRIVER //Enable to support OTA for this node (needs DualOptiBoot boot-loader to fully work) //#define MY_OTA_FIRMWARE_FEATURE #include <SPI.h> #include <MySensors.h> #include <Wire.h> #include <SI7021.h> #ifndef MY_OTA_FIRMWARE_FEATURE #include "drivers/SPIFlash/SPIFlash.cpp" #endif #include <EEPROM.h> #include <sha204_lib_return_codes.h> #include <sha204_library.h> #include <RunningAverage.h> //#include <avr/power.h> #define RELEASE "JS 2018V1" #define AVERAGES 2 // How many milli seconds between each measurement #define MEASURE_INTERVAL 60000 // How many milli seconds should we wait for OTA? #define OTA_WAIT_PERIOD 300 // FORCE_TRANSMIT_INTERVAL, this number of times of wakeup, the sensor is forced to report all values to the controller #define FORCE_TRANSMIT_INTERVAL 30 // When MEASURE_INTERVAL is 60000 and FORCE_TRANSMIT_INTERVAL is 30, we force a transmission every 30 minutes. // Between the forced transmissions a tranmission will only occur if the measured value differs from the previous measurement // HUMI_TRANSMIT_THRESHOLD tells how much the humidity should have changed since last time it was transmitted. Likewise with // TEMP_TRANSMIT_THRESHOLD for temperature threshold. #ifdef HUM #define HUMI_TRANSMIT_THRESHOLD 0.5 #endif HUM #ifdef TEMP #define TEMP_TRANSMIT_THRESHOLD 0.5 #endif // Pin definitions #define TEST_PIN A0 #define LED_PIN A2 #define ATSHA204_PIN 17 // A3 //CODE OF DOOR SKETCH************************************************ #ifdef DOOR #include <Bounce2.h> #define BUTTON_PIN_A 3 // Arduino Digital I/O pin for button/reed switch Bounce debouncer_a = Bounce(); int oldValue_a=-1; // Change to V_LIGHT if you use S_LIGHT in presentation below MyMessage msg_door_a(CHILD_ID_A,V_TRIPPED); // had to change the MyMessage var to avoid overlap #endif const int sha204Pin = ATSHA204_PIN; atsha204Class sha204(sha204Pin); SI7021 humiditySensor; SPIFlash flash(8, 0x1F65); // Sensor messages #ifdef HUM MyMessage msgHum(CHILD_ID_HUM, V_HUM); #endif #ifdef TEMP MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); #endif #ifdef BATT_SENSOR MyMessage msgBatt(BATT_SENSOR, V_VOLTAGE); #endif // Global settings int measureCount = 0; int sendBattery = 0; boolean isMetric = true; boolean highfreq = true; boolean transmission_occured = false; // Storage of old measurements #ifdef TEMP float lastTemperature = -100; #endif #ifdef HUM int lastHumidity = -100; #endif #ifdef BAT long lastBattery = -100; #endif #ifdef HUM RunningAverage raHum(AVERAGES); #endif /**************************************************** * * Setup code * ****************************************************/ void setup() { pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); Serial.begin(115200); Serial.print(F("Sensebender Micro FW ")); Serial.print(RELEASE); Serial.flush(); // First check if we should boot into test mode pinMode(TEST_PIN,INPUT); digitalWrite(TEST_PIN, HIGH); // Enable pullup #ifdef TEST_MODE if (!digitalRead(TEST_PIN)) testMode(); #endif // Make sure that ATSHA204 is not floating pinMode(ATSHA204_PIN, INPUT); digitalWrite(ATSHA204_PIN, HIGH); digitalWrite(TEST_PIN,LOW); digitalWrite(LED_PIN, HIGH); #ifdef HUM humiditySensor.begin(); #endif digitalWrite(LED_PIN, LOW); Serial.flush(); Serial.println(F(" - Online!")); isMetric = getControllerConfig().isMetric; Serial.print(F("isMetric: ")); Serial.println(isMetric); #ifdef HUM raHum.clear(); #endif #ifdef HUM sendTempHumidityMeasurements(false); #endif #ifdef TEMP sendTempHumidityMeasurements(false); #endif #ifdef BAT sendBattLevel(false); #endif #ifdef MY_OTA_FIRMWARE_FEATURE Serial.println("OTA FW update enabled"); #endif //CODE OF DOOR SKETCH************************************************ #ifdef DOOR // Define as input pinMode(BUTTON_PIN_A,INPUT); // Activate internal pull-up digitalWrite(BUTTON_PIN_A,HIGH); // After setting up the button, setup debouncer debouncer_a.attach(BUTTON_PIN_A); debouncer_a.interval(5); #endif } void presentation() { sendSketchInfo("SENSOR JANELA", RELEASE); #ifdef TEMP present(CHILD_ID_TEMP,S_TEMP); #endif #ifdef HUM present(CHILD_ID_HUM,S_HUM); #endif #ifdef BATT_SENSOR present(BATT_SENSOR, S_POWER); #endif #ifdef DOOR present(CHILD_ID_A, S_DOOR, "Persiana", true); // CHILD ID = 30 and forcing ack for this child's messages #endif } /*********************************************** * * Main loop function * ***********************************************/ void loop() { Serial.println("LOOP"); //CODE OF MOTION SKETCH************************************************ #ifdef DOOR debouncer_a.update(); // Get the update value // int value_a = debouncer_a.read(); int value_a = digitalRead(BUTTON_PIN_A); Serial.print("old:"); Serial.println(oldValue_a); Serial.print("new:"); Serial.println(value_a); if (value_a != oldValue_a) { // Send in the new value // send(msg_door_a.set(value_a==HIGH ? 1 : 0)); send(msg_door_a.set(value_a==CHANGE ? 1 : 0)); oldValue_a = value_a; } #endif measureCount ++; sendBattery ++; bool forceTransmit = false; transmission_occured = false; if (measureCount >= FORCE_TRANSMIT_INTERVAL) { // force a transmission forceTransmit = true; measureCount = 0; } #ifdef HUM #ifdef TEMP sendTempHumidityMeasurements(forceTransmit); #endif #endif /* if (sendBattery > 60) { sendBattLevel(forceTransmit); // Not needed to send battery info that often sendBattery = 0; }*/ #ifdef MY_OTA_FIRMWARE_FEATURE if (transmission_occured) { wait(OTA_WAIT_PERIOD); } sleep(digitalPinToInterrupt(BUTTON_PIN_A), CHANGE, MEASURE_INTERVAL); #endif //sleep(MEASURE_INTERVAL); } /********************************************* * * Sends temperature and humidity from Si7021 sensor * * Parameters * - force : Forces transmission of a value (even if it's the same as previous measurement) * *********************************************/ #ifdef HUM #ifdef TEMP void sendTempHumidityMeasurements(bool force) { bool tx = force; si7021_env data = humiditySensor.getHumidityAndTemperature(); raHum.addValue(data.humidityPercent); float diffTemp = abs(lastTemperature - (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths)/100.0); float diffHum = abs(lastHumidity - raHum.getAverage()); Serial.print(F("TempDiff :"));Serial.println(diffTemp); Serial.print(F("HumDiff :"));Serial.println(diffHum); if (isnan(diffHum)) tx = true; if (diffTemp >= TEMP_TRANSMIT_THRESHOLD) tx = true; if (diffHum >= HUMI_TRANSMIT_THRESHOLD) tx = true; if (tx) { measureCount = 0; float temperature = (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths) / 100.0; int humidity = data.humidityPercent; Serial.print("T: ");Serial.println(temperature); Serial.print("H: ");Serial.println(humidity); send(msgTemp.set(temperature,1)); send(msgHum.set(humidity)); lastTemperature = temperature; lastHumidity = humidity; transmission_occured = true; if (sendBattery > 60) { sendBattLevel(true); // Not needed to send battery info that often sendBattery = 0; } } } #endif #endif /******************************************** * * Sends battery information (battery percentage) * * Parameters * - force : Forces transmission of a value * *******************************************/ #ifdef BAT void sendBattLevel(bool force) { if (force) lastBattery = -1; long vcc = readVcc(); if (vcc != lastBattery) { lastBattery = vcc; #ifdef BATT_SENSOR float send_voltage = float(vcc)/1000.0f; send(msgBatt.set(send_voltage,3)); #endif // Calculate percentage vcc = vcc - 1900; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at long percent = vcc / 14.0; sendBatteryLevel(percent); transmission_occured = true; } } /******************************************* * * Internal battery ADC measuring * *******************************************/ long readVcc() { // Read 1.1V reference against AVcc // set the reference to Vcc and the measurement to the internal 1.1V reference #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) ADMUX = _BV(MUX5) | _BV(MUX0); #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) ADcdMUX = _BV(MUX3) | _BV(MUX2); #else ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #endif delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA,ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both long result = (high<<8) | low; result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 return result; // Vcc in millivolts } #endif /**************************************************** * * Verify all peripherals, and signal via the LED if any problems. * ****************************************************/ #ifdef TESTMODE void testMode() { uint8_t rx_buffer[SHA204_RSP_SIZE_MAX]; uint8_t ret_code; byte tests = 0; digitalWrite(LED_PIN, HIGH); // Turn on LED. Serial.println(F(" - TestMode")); Serial.println(F("Testing peripherals!")); Serial.flush(); Serial.print(F("-> SI7021 : ")); Serial.flush(); if (humiditySensor.begin()) { Serial.println(F("ok!")); tests ++; } else { Serial.println(F("failed!")); } Serial.flush(); Serial.print(F("-> Flash : ")); Serial.flush(); if (flash.initialize()) { Serial.println(F("ok!")); tests ++; } else { Serial.println(F("failed!")); } Serial.flush(); Serial.print(F("-> SHA204 : ")); ret_code = sha204.sha204c_wakeup(rx_buffer); Serial.flush(); if (ret_code != SHA204_SUCCESS) { Serial.print(F("Failed to wake device. Response: ")); Serial.println(ret_code, HEX); } Serial.flush(); if (ret_code == SHA204_SUCCESS) { ret_code = sha204.getSerialNumber(rx_buffer); if (ret_code != SHA204_SUCCESS) { Serial.print(F("Failed to obtain device serial number. Response: ")); Serial.println(ret_code, HEX); } else { Serial.print(F("Ok (serial : ")); for (int i=0; i<9; i++) { if (rx_buffer[i] < 0x10) { Serial.print('0'); // Because Serial.print does not 0-pad HEX } Serial.print(rx_buffer[i], HEX); } Serial.println(")"); tests ++; } } Serial.flush(); Serial.println(F("Test finished")); if (tests == 3) { Serial.println(F("Selftest ok!")); while (1) // Blink OK pattern! { digitalWrite(LED_PIN, HIGH); delay(200); digitalWrite(LED_PIN, LOW); delay(200); } } else { Serial.println(F("----> Selftest failed!")); while (1) // Blink FAILED pattern! Rappidly blinking.. { } } } #endif
Thanks,
Joaoabs
-
Well, one of the problems when buying from china is that it takes so long to get the stuff that we sometimes forgot what we ordered
It seems my RFM69's are in fact RFM69HW (eventhough the chip has a "H").
After reconfiguring the sensebender code and the raspberry configure command accordingly I got dialogue between them!
Will now try encryption
Update: It seems it's not as simple as just adding the "#define MY_RFM69_ENABLE_ENCRYPTION" in the arduino code and "#define MY_RFM69_ENABLE_ENCRYPTION" in the ./configure command for the RPI GW... Will try to sort it out and if not able to make it work, will open a different thread.
Update2: It seems it really is after all. Just needed a reboot, and the signing personalization will be re-used