Hello - thought I'd post a problem on this forum as it seems more appropriate to the issue I'm facing.
I have a Node transmitting temperature data every 8 seconds using a TMP36 sensor. That side works fine (to the extent I can tell by printing the string that's being sent over the radio and getting the LED to blink after the radio.sendWithRetry command).
I have a Gateway on the same network and frequency, no encryption etc (see sketch below). When I run the Gateway, all I get is:
Listening at 433 Mhz...
SPI Flash Init FAIL! (is chip present?)
My Moteino R4 does not have a flash chip so that message is okay. As you can see from the sketch, I have included some serial prints when data is received etc - the serial monitor is deadly silent while I can see the Node (now operating as a standalone) transmitting data (LED blinks).
I have pored through the Gateway code for 24+ hours and not getting anywhere. Even switched Moteinos but same result. Any ideas hugely appreciated. Thanks.
#include <LowPower.h> // low power library. Get Felix's version: https://github.com/LowPowerLab/LowPower
#include <RFM69.h> // RFM69 library. Get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
#include <SPIFlash.h>
#include <avr/sleep.h> // sleep library
#include <stdlib.h> // library for maths
#define NODEID 1 // Node ID used for this unit. 1 is reserved for gateway
#define NETWORKID 20 //the network ID we are on
#define FREQUENCY RF69_433MHZ
#define SERIAL_BAUD 115200 // define serial port speed
#define LED 9
RFM69 radio;
SPIFlash flash(8, 0xEF30); //EF40 for 16mbit windbond chip
bool promiscuousMode = false; //set to 'true' to sniff all packets on the same network
void setup() {
// open serial port
Serial.begin(SERIAL_BAUD);
delay(10);
// Initialize the radio
radio.initialize(FREQUENCY,NODEID,NETWORKID);
//radio.setHighPower(); //uncomment only for RFM69HW!
radio.promiscuous(promiscuousMode);
char buff[50];
sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
Serial.println(buff);
if (flash.initialize())
Serial.println("SPI Flash Init OK!");
else
Serial.println("SPI Flash Init FAIL! (is chip present?)");
}
void loop() {
int datalen;
char charbuf;
if (radio.receiveDone()) // radio finishes recieving data
{
Serial.print('[');Serial.print(radio.SENDERID, DEC);Serial.print("] ");
Serial.print(" [RX_RSSI:");Serial.print(radio.readRSSI());Serial.print("]");
if (promiscuousMode)
{
Serial.print("to [");Serial.print(radio.TARGETID, DEC);Serial.print("] ");
}
// get length
if (radio.DATALEN != 20)
{
Serial.print("Invalid payload received, not matching Payload struct!");
Serial.println(radio.DATALEN);
}
else
{
for (byte i = 0; i < radio.DATALEN; i++)
// dumps data to the serial port
Serial.print((char)radio.DATA[i]);
Serial.println();
}
// sends ack to sensor node
if (radio.ACKRequested())
{
radio.sendACK();
Serial.print(" - ACK sent"); //debugging
}
Serial.println();
Blink(LED,3);
}
}
void Blink(byte PIN, int DELAY_MS)
{
pinMode(PIN, OUTPUT);
digitalWrite(PIN,HIGH);
delay(DELAY_MS);
digitalWrite(PIN,LOW);
}
It would help if you include the node side code as well. Also, do you check the return code from radio.sendWithRetry()?
I wouldn't blink the light if you don't get a good return code...
Tom
I'd also like to see the node code.
If you really want to blink when receiving, I would wrap the receiving code in LED-HIGH and LED-LOW instead of blinking for 3ms.
What radios do you have, W or HW?
Thanks, I have the W and here's the node code:
#include <LowPower.h> // low power library. Get Felix's version: https://github.com/LowPowerLab/LowPower
#include <RFM69.h> // RFM69 library. Get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
#include <avr/sleep.h> // sleep library
#include <stdlib.h> // library for maths
// For temperature
#define aref_voltage 3.3 // we tie 3.3V to ARef and measure it with a multimeter!
#define NODEID 23 // The ID of this node. Has to be unique. 1 is reserved for the gateway!
#define NETWORKID 20 //the network ID we are on
#define GATEWAYID 1 //the gateway Moteino ID (default is 1)
#define ACK_TIME 2800 // # of ms to wait for an ack
#define FREQUENCY RF69_433MHZ
RFM69 radio;
bool requestACK=true;
// Power Management Sleep cycles
int sleepCycledefault = 1; // Sleep cycle 450*8 seconds = 1 hour. DEFAULT 450
String senseDATA; // sensor data STRING
//TMP36 Pin Variables
int tempPin = 1; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
int tempReading; // the analog reading from the sensor
void setup(void)
{
// We'll send debugging information via the Serial monitor
Serial.begin(9600);
// If you want to set the aref to something other than 5v
analogReference(EXTERNAL);
// Initialize the radio
radio.initialize(FREQUENCY,NODEID,NETWORKID);
// radio.setHighPower(); //uncomment only for RFM69HW!
}
void loop()
{
int sleepCYCLE = sleepCycledefault; // Sleep cycle reset
// read temperature
tempReading = analogRead(tempPin);
// converting that reading to voltage, which is based off the reference voltage
float voltage = tempReading * aref_voltage;
voltage /= 1024.0;
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
// PREPARE READINGS FOR TRANSMISSION
char VoltagebufTemp[10];
char voltagebufvolts[10];
senseDATA = String(NODEID);
senseDATA += ":";
senseDATA += "0"; //error level - for later
senseDATA += ":";
senseDATA += "0"; //moisture - for later
senseDATA += ":";
senseDATA += dtostrf(temperatureC,5,2,VoltagebufTemp); // convert float Temperature to string
senseDATA += ":";
senseDATA += "0"; //humidity - for later
senseDATA += ":";
senseDATA += dtostrf(voltage,4,2,voltagebufvolts);
byte sendSize = senseDATA.length();
sendSize = sendSize + 1;
char sendBuf[sendSize];
senseDATA.toCharArray(sendBuf, sendSize); // convert string to char array for transmission
Serial.print(sendBuf);
Serial.print(sendSize);
//Transmit the data
radio.sendWithRetry(GATEWAYID, sendBuf, sendSize, requestACK); // send the data
if (requestACK)
{
//wait for ack
if (waitForAck()) {
//ack recieved
} else {
//ack not recieved
sleepCYCLE = sleepCYCLE / 2; // since we didnt recieve ack, halve sleep cycle
}
}
// Randomize sleep cycle a little to prevent collisions with other nodes
sleepCYCLE = sleepCYCLE + random(8);
// POWER MANAGEMENT DEEP SLEEP
// after everything is done, go into deep sleep to save power
for ( int sleepTIME = 0; sleepTIME < sleepCYCLE; sleepTIME++ ) {
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); //sleep duration is 8 seconds multiply by the sleep cycle variable.
}
}
// Radio ACK recieve/send function
// wait a few milliseconds for proper ACK, return true if received
static bool waitForAck() {
long now = millis();
while (millis() - now <= ACK_TIME)
if (radio.ACKReceived(GATEWAYID))
return true;
return false;
}
sendWithRetry() already does the ACK work for you so why do you have separate code for that?
It's there because the sendWithRetry was a recent addition when I modified existing code but didn't take it out. That said the gateway was not receiving the transmission even before the change. I'll take the extra ACK code out or revert to just the send but still have the problem.
I guess my main concern is that your Moteinos are still working. It's really hard for this forum to fix non-working code, not without having the same hardware and putting in significant time, although it often happens because of folks that offer to help with looking at code. In your case it's just getting off the ground with a sender/receiver. For that purpose I have posted working examples that illustrate just that. Not sure what your starting point was, but I would suggest starting off from a working example and work your own sensor reading into that.
Quote from: tva164 on June 07, 2016, 08:48:00 AM
Thanks, I have the W and here's the node code:
...
//Transmit the data
radio.sendWithRetry(GATEWAYID, sendBuf, sendSize, requestACK); // send the data
HERE IS YOUR PROBLEM! sendWithRetry arguments SHOULD be:
virtual bool sendWithRetry(uint8_t toAddress, const void* buffer, uint8_t bufferSize,
uint8_t retries=2, uint8_t retryWaitTime=40); // 40ms roundtrip req for 61byte packets
Your code should read:
if (radio.sendWithRetry(y(GATEWAYID, sendBuf, sendSize)) // defaults should be fine and this will be true IFF you received an ACK. No further testing is necessary.
Quote
if (requestACK)
{
//wait for ack
if (waitForAck()) {
//ack recieved
} else {
//ack not recieved
sleepCYCLE = sleepCYCLE / 2; // since we didnt recieve ack, halve sleep cycle
}
}
// Randomize sleep cycle a little to prevent collisions with other nodes
sleepCYCLE = sleepCYCLE + random(8);
// POWER MANAGEMENT DEEP SLEEP
// after everything is done, go into deep sleep to save power
for ( int sleepTIME = 0; sleepTIME < sleepCYCLE; sleepTIME++ ) {
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); //sleep duration is 8 seconds multiply by the sleep cycle variable.
}
}
// Radio ACK recieve/send function
// wait a few milliseconds for proper ACK, return true if received
static bool waitForAck() {
long now = millis();
while (millis() - now <= ACK_TIME)
if (radio.ACKReceived(GATEWAYID))
return true;
return false;
}
Hi Felix - thanks for your suggestion. So it was back to basics, and to be extra certain I reinstalled Arduino on my laptop, reinstalled all the libraries with fresh downloads and uploaded RFM69 Node and Gateway sketches into two R4's. I have the node connected via USB to my laptop, and the gateway as a standalone powered by 4 1.5v AA batteries.
The LEDs on both are blinking away, and when I disconnect the node, the LED on gateway stops blinking as well - this shows there is radio activity between them.
But, there is no ACK back from the gateway to the node and I see the following:
Sending[26]: 123 ABCDEFGHIJKLMNOPQRSTUV nothing...
Sending[27]: 123 ABCDEFGHIJKLMNOPQRSTUVW nothing...
Sending[28]: 123 ABCDEFGHIJKLMNOPQRSTUVWX nothing...
Now when I switch the node to the battery pack it starts up again and the LED blinks indicating transmission, but the gateway is silent - no light and all I have on Serial Monitor is:
Listening at 433 Mhz...
SPI Flash MEM not found (is chip soldered?)...
RFM69_ATC Enabled (Auto Transmission Control)
I have even swapped the sketches on the two Moteinos and the result is the same. I have a third Moteino that I know works, and swapped it for each of the two existing Moteinos and the problem is the same. There is something very odd going on with gateways - any thoughts?
Tom - thanks for the correction - it looks like there's a more basic problem with Moteino gateways that I need to address first.
I suggest that you either change your baud rate from 9600 to 115200 and/or eliminate all the Serial.prints BEFORE you get around to sending the requested ACK. You've got an endpoint waiting for an ack and you're busy printing status...
Tom
Thanks Tom, I'll try that but I just came back to say there seems to be a distance issue. I took the node really close to the gateway (antennae almost touching), and here's the output I captured from the node:
Sending[10]: 123 ABCDEF ok!
Sending[11]: 123 ABCDEFG ok!
Sending[12]: 123 ABCDEFGH ok!
Sending[13]: 123 ABCDEFGHI ok!
[1] ACK TEST [RX_RSSI:-81] - ACK sent
Sending[14]: 123 ABCDEFGHIJ ok!
Sending[15]: 123 ABCDEFGHIJK ok!
Sending[16]: 123 ABCDEFGHIJKL ok!
[1] ACK TEST [RX_RSSI:-81] - ACK sent
Sending[17]: 123 ABCDEFGHIJKLM ok!
Sending[18]: 123 ABCDEFGHIJKLMN ok!
Sending[19]: 123 ABCDEFGHIJKLMNO ok!
[1] ACK TEST [RX_RSSI:-83] - ACK sent
Sending[20]: 123 ABCDEFGHIJKLMNOP ok!
Sending[21]: 123 ABCDEFGHIJKLMNOPQ ok!
[1] ACK TEST [RX_RSSI:-82] - ACK sent
Sending[22]: 123 ABCDEFGHIJKLMNOPQR ok!
Sending[23]: 123 ABCDEFGHIJKLMNOPQRS ok!
Sending[24]: 123 ABCDEFGHIJKLMNOPQRST ok!
[1] ACK TEST [RX_RSSI:-83] - ACK sent
Sending[25]: 123 ABCDEFGHIJKLMNOPQRSTU ok!
[1] ACK TEST [RX_RSSI:-82] - ACK sent
Sending[26]: 123 ABCDEFGHIJKLMNOPQRSTUV ok!
Sending[27]: 123 ABCDEFGHIJKLMNOPQRSTUVW ok!
[1] ACK TEST [RX_RSSI:-81] - ACK sent
Sending[28]: 123 ABCDEFGHIJKLMNOPQRSTUVWX ok!
Sending[29]: 123 ABCDEFGHIJKLMNOPQRSTUVWXY ok!
Sending[30]: 123 ABCDEFGHIJKLMNOPQRSTUVWXYZ ok!
ok!
Sending[1]: 1 ok!
[1] ACK TEST [RX_RSSI:-84] - ACK sent
Sending[2]: 12 nothing...
Sending[3]: 123 ok!
Sending[4]: 123 ok!
Sending[5]: 123 A ok!
[1] ACK TEST [RX_RSSI:-82] - ACK sent
Sending[6]: 123 AB ok!
Sending[7]: 123 ABC ok!
Sending[8]: 123 ABCD ok!
Sending[9]: 123 ABCDE ok!
Sending[10]: 123 ABCDEF ok!
[1] ACK TEST [RX_RSSI:-83] - ACK sent
Sending[11]: 123 ABCDEFG ok!
Sending[12]: 123 ABCDEFGH ok!
[1] ACK TEST [RX_RSSI:-83] - ACK sent
Sending[13]: 123 ABCDEFGHI ok!
Sending[14]: 123 ABCDEFGHIJ ok!
Sending[15]: 123 ABCDEFGHIJK ok!
[1] ACK TEST [RX_RSSI:-84] - ACK sent
Sending[16]: 123 ABCDEFGHIJKL ok!
Sending[17]: 123 ABCDEFGHIJKLM ok!
[1] ACK TEST [RX_RSSI:-86] - ACK sent
Sending[18]: 123 ABCDEFGHIJKLMN ok!
Sending[19]: 123 ABCDEFGHIJKLMNO ok!
Sending[20]: 123 ABCDEFGHIJKLMNOP nothing...
Sending[21]: 123 ABCDEFGHIJKLMNOPQ ok!
Sending[22]: 123 ABCDEFGHIJKLMNOPQR ok!
Sending[23]: 123 ABCDEFGHIJKLMNOPQRS nothing...
Sending[24]: 123 ABCDEFGHIJKLMNOPQRST nothing...
Sending[25]: 123 ABCDEFGHIJKLMNOPQRSTU ok!
Sending[26]: 123 ABCDEFGHIJKLMNOPQRSTUV ok!
Sending[27]: 123 ABCDEFGHIJKLMNOPQRSTUVW ok!
Sending[28]: 123 ABCDEFGHIJKLMNOPQRSTUVWX ok!
Sending[29]: 123 ABCDEFGHIJKLMNOPQRSTUVWXY nothing...
Seems to show some life, but I do not know enough to decipher from the log what's going on. Thanks.
Tom, baud rate is 115200 and these are the standard Node and Gateway sketches from Felix's GitHub page (RFM69).
Quote from: tva164 on June 07, 2016, 05:12:36 PM
Tom, baud rate is 115200 and these are the standard Node and Gateway sketches from Felix's GitHub page (RFM69).
So the code you posted in reply #3 isn't correct where is has:
// We'll send debugging information via the Serial monitor
Serial.begin(9600);
In that case, I can't help you.
Hi Tom it looks like some wires crossed (pardon the pun) - I was referring to the basic Node and Gateway sketches that Felix suggested I try out and the last couple of posts relate to that. The baud rate on the sketch you referred to is still 9600 - I will make those changes and test again, but from my last post (5:11pm) it seems like there is a more fundamental problem - the radios are working but the gateway is not picking up the node transmissions unless they are both kept really close to each other.
Quote from: tva164 on June 08, 2016, 03:44:51 AM
the radios are working but the gateway is not picking up the node transmissions unless they are both kept really close to each other.
This smells like the standard isRFM69HW problem. Are you sure you're using a W and not an HW?
Tom
QuoteThis smells like the standard isRFM69HW problem. Are you sure you're using a W and not an HW?
This is what it turned out to be. Problem now fixed, the original sketches are loaded and it works a charm. I will now go back on some of your earlier advice and clean up the code.
Thanks for your help and while it turned out to be a simple thing in the end it was valuable learning for me. (I had tested the R4s once after purchasing them over a year ago and they have sat in a drawer ever since - my fault for not checking version when I pulled them out to start this project).
This is what makes this community so great - keep up the fantastic work you're doing.
I know this is an old thread, but I came across it trying to debug a similar problem I am seeing with my mote gateway communication sketches. Can someone please explain what the "standard isRFM69HW problem" is?
There are two flavors of transceivers for each freq: standard and high power.
You need to tell the code which version of chips you have. I assume that what is meant by that statement is a mismatch between code setting and hw.
https://lowpowerlab.com/guide/moteino/transceivers/
(https://lowpowerlab.com/wp-content/uploads/2016/09/LowPowerLab_transceivers-1.png)
Got it, thanks!