Gateway Web UI Doesn't Send Data to Nodes

Started by pigeon_plum, March 21, 2017, 09:21:15 AM

pigeon_plum

Hello All,

I have a MightyHat set up with a Raspberry Pi 3, and a three-button SwitchMote (model R2). Everything is configured with RFM_69HW at 433 MHz.

I have set up the gateway and the node, and the node communicates with the web UI and the state of the switches is reflected in the UI on the gateway. It seems like everything is set up and working properly, however pushing any of the buttons on the web UI doesn't change the state of any of the switches on the SwitchMote.

I found this possible solution while I was reading through the forums, but after updating my sketch to the PiGateway sketch I still have the same problem:
https://lowpowerlab.com/forum/pi-gateway/gateway-moteino-not-sending-command-to-switchmote/

Has anyone else seen this before? I feel like I'm missing something simple.

Felix

So you have a HW on your MHat. Is your PiGateway sketch running on it configured with the IS_RFM69HW flag?

pigeon_plum

So I went back to verify that the IS_RFM69HW flag was properly configured, and realized that after I switched from the original Gateway sketch to the PiGateway sketch, the node (switchmote) wasn't communicating with the gateway at all anymore.

Here is the sketch I am using for the gateway:

// **********************************************************************************
#include <RFM69.h>         //get it here: https://github.com/lowpowerlab/rfm69
#include <RFM69_ATC.h>     //get it here: https://github.com/lowpowerlab/RFM69
#include <RFM69_OTA.h>     //get it here: https://github.com/lowpowerlab/RFM69
#include <SPIFlash.h>      //get it here: https://github.com/lowpowerlab/spiflash
#include <SPI.h>           //included with Arduino IDE (www.arduino.cc)

//****************************************************************************************************************
//**** IMPORTANT RADIO SETTINGS - YOU MUST CHANGE/CONFIGURE TO MATCH YOUR HARDWARE TRANSCEIVER CONFIGURATION! ****
//****************************************************************************************************************
#define NODEID          1 //the ID of this node
#define NETWORKID     10 //the network ID of all nodes this node listens/talks to
#define FREQUENCY     RF69_433MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ)
#define ENCRYPTKEY    "sixteensixteen16" //identical 16 characters/bytes on all nodes, not more not less!
#define IS_RFM69HW    //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define ACK_TIME       30  // # of ms to wait for an ack packet
//*****************************************************************************************************************************
#define ENABLE_ATC    //comment out this line to disable AUTO TRANSMISSION CONTROL
#define ATC_RSSI      -75  //target RSSI for RFM69_ATC (recommended > -80)
//*****************************************************************************************************************************
// Serial baud rate must match your Pi/host computer serial port baud rate!
#define SERIAL_EN     //comment out if you don't want any serial verbose output
#define SERIAL_BAUD  19200
//*****************************************************************************************************************************

#ifdef __AVR_ATmega1284P__
  #define LED           15 // Moteino MEGAs have LEDs on D15
  #define FLASH_SS      23 // and FLASH SS on D23
#else
  #define LED           9 // Moteinos have LEDs on D9
  #define FLASH_SS      8 // and FLASH SS on D8
#endif

#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

#ifdef ENABLE_ATC
  RFM69_ATC radio;
#else
  RFM69 radio;
#endif

SPIFlash flash(FLASH_SS, 0xEF30); //EF30 for 4mbit Windbond FlashMEM 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);
  
#ifdef ENABLE_ATC
  radio.enableAutoPower(ATC_RSSI);
#endif
  
  char buff[50];
  sprintf(buff, "\nTransmitting at %d Mhz...", radio.getFrequency()/1000000);
  DEBUGln(buff);

  if (flash.initialize())
  {
    DEBUGln("SPI Flash Init OK!");
  }
  else
  {
    DEBUGln("SPI FlashMEM not found (is chip onboard?)");
  }
}

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);
}


These are the configuration settings I have on the Switchmote that I pulled via a serial link through putty:
f - set frequency band (set to: 433mhz)
i - set node ID (set to: 20)
n - set network ID (set to: 10)
w - set RFM69 type (set to: HW)
e - set encryption key (set to: 'sixteensixteen16')
d - set description (set to: 'firstswitc')

Pushing the buttons on the front of the Switchmote does send data back through serial link that seems to verify that the Switchmote sketch is running properly as well.

Felix

Hold on, I think you should be running this sketch instead if you have a MHat: https://github.com/LowPowerLab/RFM69/blob/master/Examples/MightyHat/MightyHat.ino

Other thoughts:
Are both units having the same latest version of RFM69 lib?
Seetings look good, and  as long as the frequency and the IS_RFM69HW matched the hardware it should just work.

pigeon_plum

OK I'm making progress now! I put the MightyHat sketch on the gateway which helped out a lot. Now that the LCD screen on the MightyHat is working I can confirm that the SwitchMote node is communicating with the gateway because when I push a button on the SwitchMote the LCD screen on the MightHat shows which button was pushed. However, no information is being passed to the Raspberry Pi from there.

I went ahead and reinstalled the gatewaysetup.sh script just to make sure that was done correctly. Any idea on where to go from here?

Felix

Sounds like your serial port might not be working. Is this a  PI3?
Make sure the GPIO serial (/dev/ttyAMA0) is enabled. I've posted on this in the forum before.
Check the logs/gateway.sys.log for any errors regarding this or anything else.

pigeon_plum

Yes, this is the Pi 3. Tonight I tried a few different Raspbian distributions, starting with the 2016-05-27-raspbian-jesse-lite and am currently using the 2017-03-02-raspbian-jesse image. I disabled the serial console as shown here: https://lowpowerlab.com/guide/gateway/possible-known-issues/. I also followed the instructions here: https://lowpowerlab.com/guide/mightyhat/pi3-compatibility/ and I can open minicom but I'm not really sure what I should be looking for.

This is what my /boot/config.txt file looks like:

# Enable audio (loads snd_bcm2835)
dtparam=audio=on
enable_uart=1

dtoverlay=pi3-disable-bt


The output of /logs/gateway.sys.log just repeats the same line over and over:

/bin/sh: 1: /usr/bin/node: not found


I got the same results with both versions of Raspbian that I tried, and the Moteino Gateway Dashboard just says "waiting for socket connection". I'm not really sure where to go from here, it feels kind of like I'm going in circles now.

The weird thing that I keep thinking about is that when I first configured everything (using the Gateway sketch instead of the MightyHat sketch) I got everything talking together for the most part, but now it's not communicating at all.

rd909

Sounds like you are most of the way there if you are able to access the web interface, but it is complaining about not being able to open the socket. The missing /usr/bin/node is a good clue; either you don't have nodejs installed or it is the wrong version. Did you use the installation instructions here?

https://github.com/LowPowerLab/RaspberryPi-Gateway

You may need to install again, because npm goes through all the dependencies when you run "npm install" from the root of the gateway directory. Watch for errors related to node. Depending on your version of the OS you may be able to run "apt-get install nodejs". Versions can be picky though so watch that. I ended up upgrading mine so I could run hap-nodejs and it is still compatible with the moteino gateway. This might also be helpful:

https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions

Rod

Felix

As Rod pointed out, looks like there's a problem with node not being found.

pigeon_plum

I haven't been using those instructions, I've been using the setup script from here:
https://lowpowerlab.com/guide/gateway/setup-software/

It does do this, though, which I hadn't noticed before:

Connecting to nodejs.org (nodejs.org)|104.20.23.46|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11482171 (11M) [application/gzip]
Saving to: 'node-v4.6.2-linux-armv6l.tar.gz'

node-v4.6.2-linux-a 100%[=====================>]  10.95M  2.32MB/s   in 4.9s   

2017-03-30 02:30:18 (2.25 MB/s) - 'node-v4.6.2-linux-armv6l.tar.gz' saved [11482171/11482171]

Creating symbolic link to node in /usr/bin/
Creating symbolic link to nodejs in /usr/bin/
Creating symbolic link to npm in /usr/bin/
************* STEP: Setup Gateway app & dependencies *************
Reinitialized existing Git repository in /home/pi/gateway/.git/
fatal: remote origin already exists.
From https://github.com/LowPowerLab/RaspberryPi-Gateway
 * branch            master     -> FETCH_HEAD
Already up-to-date.
sudo: npm: command not found
sudo: npm: command not found


After seeing that I tried "sudo apt-get install npm" but this didn't change anything when I ran the script again. I also googled around for some other possible solutions including some possible broken and/or missing symbolic links, but nothing I have tried so far works.

Felix

So it installed node and npm but where ???
What's in /usr/bin/ ?

If I do which npm I find that npm is here: /usr/bin/npm

pigeon_plum

#11
I tried which npm and it didn't return anything, so I went into /usr/bin and a file named npm was there (in red, meaning it's an archived file?). I tried a few other things but despite the file being there, npm didn't seem to exist despite having been installed.

It seems like npm/node doesn't get along well with the Raspberry Pi sometimes, but I ran across another page (http://weworkweplay.com/play/raspberry-pi-nodejs/) which had these instructions:

wget http://node-arm.herokuapp.com/node_latest_armhf.deb 
sudo dpkg -i node_latest_armhf.deb


(I also had to apt-get remove nodejs-legacy which is a package that I installed earlier in an effort to try and solve this problem)

After running these commands, and then running the gateway setup script again, I no longer get the "npm: command not found" error from my previous post. Also, which npm now returns /usr/local/bin/npm instead of nothing, like it was doing before, but this doesn't match your /usr/bin/npm. npm -v returns 2.14.7. But the gateway dashboard still says "Waiting on socket connection".

I am also questioning whether I have an appropriate version of Raspbian installed:
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 8.0 (jessie)
Release:	8.0
Codename:	jessie

Felix

This should all just work, the setup script was tested with the latest Jessie image. It's really weird that you run into these problems. Not sure how to help, the software is free and as is and it's a best effort to make it work for everyone on a known/tested platform like the Pi+Raspbian.