Author Topic: Node not displaying all data [solved]  (Read 3274 times)

ekoelle

  • NewMember
  • *
  • Posts: 16
Node not displaying all data [solved]
« on: August 31, 2015, 09:14:12 PM »
Hello all. Just getting back into the Moteino stuff after a long absence and I'm a little perplexed. I have a pi gateway setup with the image from github and i have a simple node with a DHT22 sensor. I repurposed an example from codebender.cc using a DHT11 and everything appears to be communicating just fine except that in my gateway I only see the humidity info and not the temp or battery voltage that I'm also sending. Serial output confirms that the temp and battery data is there. Code is below. Let me know if you see anything glaring that i'm missing. Thanks in advance.

Code: [Select]
// Moteino battery operated wireless temp/humidity sensor
//    Based on: http://lowpowerlab.com/blog/2013/08/27/mailbox-notifier-project-upgrade/
// battery monitor wiring: (see above)

#include <DHT.h>   // DHT11 temp/humidity sensor
#include <RFM69.h>    //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
#include <LowPower.h> //get library from: https://github.com/lowpowerlab/lowpower

#define DHTTYPE       DHT22
#define DHTPIN   7
#define DHTENABLE   5
#define BATTERYSENSE  A2  // Use a 4.7k  resistor
#define NODEID        99    //unique for each node on same network
#define NETWORKID     200  //the same on all nodes that talk to each other
#define GATEWAYID     1
#define FREQUENCY     RF69_915MHZ
#define ENCRYPTKEY    "****************" //exactly the same 16 characters/bytes on all nodes!
#define ACK_TIME      30 // max # of ms to wait for an ack
#define ONBOARDLED     9  // Moteinos have LEDs on D9
#define SLEEPCYCLES    8  // Each low power sleep cycle is about 8 secs

RFM69 radio;
DHT dht(DHTPIN, DHTTYPE);
char sendBuf[32] = {0};
byte sendLen = 0;
char* BATstr="B:5.00v";

void setup()
{
//pinMode(LIGHTENABLE, OUTPUT);
pinMode(DHTENABLE, OUTPUT);
Serial.begin(115200);
Serial.println("Moteino temp/humidity");
dht.begin();
    radio.initialize(FREQUENCY,NODEID,NETWORKID);
    radio.encrypt(ENCRYPTKEY);
    char buff[50];
    sprintf(buff, "Transmitting at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
    Serial.println(buff);
}

void loop()
{
int batteryReading = analogRead(BATTERYSENSE);

digitalWrite(DHTENABLE, HIGH);
  delay(1000);                  // waits for a second for stable readings
float battV = (batteryReading * 3.3 * 9)/(1023*2.8776);
    dtostrf(battV, 3,2, BATstr);
int dhttemp = dht.readTemperature(true);
int dhthum = dht.readHumidity();
  digitalWrite(DHTENABLE, LOW);

// Format the reading to send to gateway
sprintf(sendBuf,"N:%d T:%d H:%d B:%s", NODEID, dhttemp, dhthum, BATstr);
    sendLen = strlen(sendBuf);
    Serial.print(sendBuf);
   
//  Send the reading and check for ACK
    if (radio.sendWithRetry(GATEWAYID, sendBuf, sendLen))
    {
      Serial.print(" ACKed! RSSI:");
      Serial.println(radio.RSSI);
    }
    else Serial.println(" No ACK..");
    Serial.flush();  // Prevents garbled serial output due to sleep-power down

// Put radio and moteino in low power sleep mode
radio.sleep();
for (int i = 1; i <= SLEEPCYCLES; i++) {
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
}
}


« Last Edit: September 02, 2015, 09:31:27 AM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Node not displaying all data
« Reply #1 on: September 01, 2015, 07:50:47 AM »
Your sketch looks good.
What are you receiving on the gateway end?
You're probably not reading the serial all the way from the gateway Moteino, is my guess.

ekoelle

  • NewMember
  • *
  • Posts: 16
Re: Node not displaying all data
« Reply #2 on: September 01, 2015, 08:56:33 AM »
I'm using the standard example for the moteino on the pi gateway. Screenshot below of what I see on the gateway interface.

Code: [Select]
#include <RFM69.h>         //get it here: http://github.com/lowpowerlab/rfm69
#include <SPIFlash.h>      //get it here: http://github.com/lowpowerlab/spiflash
#include <WirelessHEX69.h> //get it here: https://github.com/LowPowerLab/WirelessProgramming
#include <SPI.h>           //comes with Arduino IDE (www.arduino.cc)

//*****************************************************************************************************************************
// ADJUST THE SETTINGS BELOW DEPENDING ON YOUR HARDWARE/SITUATION!
//*****************************************************************************************************************************
#define NODEID          1
#define NETWORKID     200
#define FREQUENCY     RF69_915MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ)
#define ENCRYPTKEY    "sampleEncryptKey" //has to be same 16 characters/bytes on all nodes, not more not less!
//#define IS_RFM69HW    //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define LED             9
#define FLASH_CS        8
#define SERIAL_BAUD 115200
#define SERIAL_EN     //comment out if you don't want any serial verbose output
#define ACK_TIME       30  // # of ms to wait for an ack
//*****************************************************************************************************************************

#ifdef SERIAL_EN
  #define DEBUG(input)   {Serial.print(input); delay(1);}
  #define DEBUGln(input) {Serial.println(input); delay(1);}
#else
  #define DEBUG(input);
  #define DEBUGln(input);
#endif

RFM69 radio;
SPIFlash flash(FLASH_CS, 0xEF30); //EF40 for 16mbit windbond chip

void setup() {
  Serial.begin(SERIAL_BAUD);
  delay(10);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
#ifdef IS_RFM69HW
  radio.setHighPower(); //uncomment only for RFM69HW!
#endif
  radio.encrypt(ENCRYPTKEY);
  char buff[50];
  sprintf(buff, "\nListening at %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  DEBUGln(buff);
  if (flash.initialize())
  {
    DEBUGln("SPI Flash Init OK!");
  }
  else
    DEBUGln("SPI Flash Init FAIL! (is chip present?)");
}

byte ackCount=0;
byte inputLen=0;
char input[64];
byte buff[61];
String inputstr;
void loop() {
  inputLen = readSerialLine(input);
  inputstr = String(input);
  inputstr.toUpperCase();
 
  if (inputLen > 0)
  {
    if (inputstr.equals("KEY?"))
    {
      DEBUG("ENCRYPTKEY:");
      DEBUG(ENCRYPTKEY);
    }
   
    byte targetId = inputstr.toInt(); //extract ID if any
    byte colonIndex = inputstr.indexOf(":"); //find position of first colon
    if (targetId > 0) inputstr = inputstr.substring(colonIndex+1); //trim "ID:" if any
    if (targetId > 0 && targetId != NODEID && targetId != RF69_BROADCAST_ADDR && colonIndex>0 && colonIndex<4 && inputstr.length()>0)
    {
     
      inputstr.getBytes(buff, 61);
      //DEBUGln((char*)buff);
      //DEBUGln(targetId);
      //DEBUGln(colonIndex);
      if (radio.sendWithRetry(targetId, buff, inputstr.length()))
      {
        DEBUGln("ACK:OK");
      }
      else
        DEBUGln("ACK:NOK");
    }
  }

  if (radio.receiveDone())
  {
    int rssi = radio.RSSI;
    DEBUG('[');DEBUG(radio.SENDERID);DEBUG("] ");
    if (radio.DATALEN > 0)
    {
      for (byte i = 0; i < radio.DATALEN; i++)
        DEBUG((char)radio.DATA[i]);
      DEBUG("   [RSSI:");DEBUG(rssi);DEBUG("]");
    }

    CheckForWirelessHEX(radio, flash, false); //non verbose DEBUG

    if (radio.ACKRequested())
    {
      byte theNodeID = radio.SENDERID;
      radio.sendACK();
      DEBUG("[ACK-sent]");
    }
    DEBUGln();
    Blink(LED,3);
  }
}

void Blink(byte PIN, int DELAY_MS)
{
  pinMode(PIN, OUTPUT);
  digitalWrite(PIN,HIGH);
  delay(DELAY_MS);
  digitalWrite(PIN,LOW);
}


Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Node not displaying all data
« Reply #3 on: September 01, 2015, 01:03:01 PM »
Ok, the problem is that T. N and B are not defined in metrics.js, only H is. So they are not recognized and probably placed in gateway_nonmatches.db.
Follow the example of H to create your own metrics definitions, here's an example:

Code: [Select]
F : { name:'F', regexp:/F\:(-?\d+\.\d+)/i, value:'', unit:'°', pin:1 }

ekoelle

  • NewMember
  • *
  • Posts: 16
Re: Node not displaying all data
« Reply #4 on: September 01, 2015, 02:06:01 PM »
Thank you sir. Will give it a shot later tonight and let you know how it goes.

ekoelle

  • NewMember
  • *
  • Posts: 16
Re: Node not displaying all data
« Reply #5 on: September 01, 2015, 02:39:52 PM »
Ok, the problem is that T. N and B are not defined in metrics.js, only H is. So they are not recognized and probably placed in gateway_nonmatches.db.
Follow the example of H to create your own metrics definitions, here's an example:

Code: [Select]
F : { name:'F', regexp:/F\:(-?\d+\.\d+)/i, value:'', unit:'°', pin:1 }

Decided not to wait and changed the T to an F and the B to V and now I get the temp reading but I'm getting a  leading decimal point on the temperature. So .79 instead of 79. Shows as 79 in the serial monitor.

*Update* Looks like there are two regular expressions in the metrics.js file, FH and F. I'm not so good with regular expressions so I'm not sure what the original purpose is for the separate entries. If i remove the FH entry will I break weathershield functionality? Or, what is the purpose of the division by 100 for the FH entry?
« Last Edit: September 01, 2015, 03:28:03 PM by ekoelle »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Node not displaying all data
« Reply #6 on: September 01, 2015, 03:36:38 PM »
The weather shield send the temperature without decimals, so the gateway has a valuation function that divides the sent value by 100. You can remove that if you don't want the division.
You can just make something custom like "FX" instead and send from the node with that prefix, then you don't need to remove any of the existing entries.

ekoelle

  • NewMember
  • *
  • Posts: 16
Re: Node not displaying all data
« Reply #7 on: September 01, 2015, 05:00:51 PM »
Got it. Working as expected now. Thank you!