LowPowerLab Forum

Hardware support => Moteino => Topic started by: byerss on January 11, 2014, 02:43:12 PM

Title: Wireless Programming Handshake Fail
Post by: byerss on January 11, 2014, 02:43:12 PM
I am trying to test the wireless programming abilities of the Moteino but I seem to have hit a wall.

Node:
Flashed with WirelessProgramming_node.ino
Node ID: 55
Network ID: 250
FREQUENCY:   433MHZ
Flash Chip Installed

Gateway:
Flashed with WirelessProgramming_gateway.ino
Node ID: 5
Network ID: 250
FREQUENCY:   433MHZ
Flash Chip Installed

My host computer has Python 2.7.3 installed.

C:\Python27>WirelessProgramming.py -f node.hex -s COM5 -b 115200
TO:55
Moteino: [TO:55:OK]
TARGET SET OK
File found, passing to Moteino...
FLX?

FLX?

FLX?

FLX?

Moteino: [Handshake fail]
FLX?

No response from Moteino, exiting...


Could you elaborate on which handshake is failing? Is it the handshake between the host computer and the gateway Moteino or the Gateway-to-Node wireless handshake?


Title: Re: Wireless Programming Handshake Fail
Post by: Felix on January 11, 2014, 05:09:15 PM
First of all please make sure you're running the latest code for wireless programming, there have been some recent updates.
Then on the target you have to use the CheckForWirelessHex() function as shown here (https://github.com/LowPowerLab/RFM69/blob/master/Examples/WirelessProgramming_node/WirelessProgramming_node.ino).
I would start by running the provided examples without modification (except basic settings like frequency and setting IS_RFM69HW if you got an RFM69HW unit).
Connect the target to another FTDI adapter so you could open a serial terminal to see the output from that. When a wireless programming handshake is received you should see the output reflecting that.
From your provided output it seems the handshake is never received by the target.
Title: Re: Wireless Programming Handshake Fail
Post by: byerss on January 11, 2014, 09:00:40 PM
Okay, found the problem.

In your example code for the RFN69 WirelessProgramming_gateway.ino you have encryption enabled, but for the WirelessProgramming_node.ino encryption was disabled.

Disabled encryption on the gateway and the wireless programming worked like a charm!  ;D
Title: Re: Wireless Programming Handshake Fail
Post by: Felix on January 11, 2014, 09:38:00 PM
Awesome! Like magic when it works huh.. ;)
Title: Re: Wireless Programming Handshake Fail
Post by: djash40 on November 05, 2016, 04:10:33 PM
I've been trying to get wireless programming working and the error I got led me to this thread.
So I have encryption enabled and I can't get it to work command line linux.
FLX?
No response from Moteino, exiting...

So must I disable encryption for this to work?
Title: Re: Wireless Programming Handshake Fail
Post by: Felix on November 06, 2016, 08:51:04 PM
Encryption can and should be left on whenever you want to have some security.
Just make sure the keys match in your programmer and your programmed nodes. The given examples have sample keys that will probably not match your network settings, so you must always visit the settings section in any sketch before you upload code to your Moteino.
Let me know how it goes.
Title: Re: Wireless Programming Handshake Fail
Post by: djash40 on November 12, 2016, 03:16:30 PM
python WirelessProgramming.py -f WirelessProgramming_NodeTestNode4-110516.ino.hex -t 4 -s /dev/ttyUSB2 -b 115200
TO:4
Moteino: [TO:4:OK]
TARGET SET OK
File found, passing to Moteino...
FLX?

FLX?

FLX?

FLX?

No response from Moteino, exiting...
Using linux os. Still not working gateway and node setting are right to my knowledge. I'll include to verify.
I made sure I have the latest version of your libraries too. Not sure what to do next. If someone spots a mistake I may have made please advise.
// **********************************************************************************
// This sketch is an example of how wireless programming can be achieved with a Moteino
// that was loaded with a custom 1k bootloader (DualOptiboot) that is capable of loading
// a new sketch from an external SPI flash chip
// This is the GATEWAY node, it does not need a custom Optiboot nor any external FLASH memory chip
// (ONLY the target node will need those)
// The sketch includes logic to receive the new sketch from the serial port (from a host computer) and
// transmit it wirelessly to the target node
// The handshake protocol that receives the sketch from the serial port
// is handled by the SPIFLash/WirelessHEX69 library, which also relies on the RFM69 library
// These libraries and custom 1k Optiboot bootloader for the target node are at: http://github.com/lowpowerlab
// **********************************************************************************
// Copyright Felix Rusu, LowPowerLab.com
// Library and code by Felix Rusu - [email protected]
// **********************************************************************************
// License
// **********************************************************************************
// This program is free software; you can redistribute it
// and/or modify it under the terms of the GNU General   
// Public License as published by the Free Software       
// Foundation; either version 3 of the License, or       
// (at your option) any later version.                   
//                                                       
// This program is distributed in the hope that it will   
// be useful, but WITHOUT ANY WARRANTY; without even the 
// implied warranty of MERCHANTABILITY or FITNESS FOR A   
// PARTICULAR PURPOSE. See the GNU General Public       
// License for more details.                             
//                                                       
// You should have received a copy of the GNU General   
// Public License along with this program.
// If not, see <http://www.gnu.org/licenses/>.
//                                                       
// Licence can be viewed at                               
// http://www.gnu.org/licenses/gpl-3.0.txt
//
// Please maintain this license information along with authorship
// and copyright notices in any redistribution of this code
// **********************************************************************************
#include <RFM69.h>          //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
#include <SPIFlash.h>      //get it here: https://www.github.com/lowpowerlab/spiflash
#include <WirelessHEX69.h> //get it here: https://github.com/LowPowerLab/WirelessProgramming/tree/master/WirelessHEX69

#define NODEID        3    //unique for each node on same network
#define NETWORKID     100  //the same on all nodes that talk to each other
//#define GATEWAYID     1
#define FREQUENCY     RF69_915MHZ
#define ENCRYPTKEY    "xxxxxxxxxxxxxxxx" // xed out for forum: exactly the same 16 characters/bytes on all nodes!
//#define SEND_LOOPS   15000
#define SERIAL_BAUD   115200
//#define IS_RFM69HW    //uncomment only for RFM69HW! Leave outif you have RFM69W!
#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
#define ACK_TIME    50  // # of ms to wait for an ack
#define TIMEOUT     3000

#ifdef __AVR_ATmega1284P__
  #define LED           15 // Moteino MEGAs have LEDs on D15
#else
  #define LED           9 // Moteinos hsave LEDs on D9
#endif

RFM69 radio;
char c = 0;
char input[64]; //serial input buffer
byte targetID=0;

void setup(){
  Serial.begin(SERIAL_BAUD);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  radio.encrypt(ENCRYPTKEY); //OPTIONAL
#ifdef IS_RFM69HW
  radio.setHighPower(); //only for RFM69HW!
#endif
  Serial.println("Start wireless gateway...");
  Serial.println("Sketch is WirelessProgramming_gateway110216");
    Serial.print("Node ");
    Serial.println(NODEID);
    Serial.print("NetworkID ");
    Serial.println(NETWORKID);
}

void loop(){
  byte inputLen = readSerialLine(input, 10, 64, 100); //readSerialLine(char* input, char endOfLineChar=10, byte maxLength=64, uint16_t timeout=1000);
 
  if (inputLen==4 && input[0]=='F' && input[1]=='L' && input[2]=='X' && input[3]=='?') {
    if (targetID==0)
      Serial.println("TO?");
    else
      CheckForSerialHEX((byte*)input, inputLen, radio, targetID, TIMEOUT, ACK_TIME, false);
  }
  else if (inputLen>3 && inputLen<=6 && input[0]=='T' && input[1]=='O' && input[2]==':')
  {
    byte newTarget=0;
    for (byte i = 3; i<inputLen; i++) //up to 3 characters for target ID
      if (input[i] >=48 && input[i]<=57)
        newTarget = newTarget*10+input[i]-48;
      else
      {
        newTarget=0;
        break;
      }
    if (newTarget>0)
    {
      targetID = newTarget;
      Serial.print("TO:");
      Serial.print(newTarget);
      Serial.println(":OK");
    }
    else
    {
      Serial.print(input);
      Serial.print(":INV");
    }
  }
  else if (inputLen>0) { //just echo back
    Serial.print("SERIAL IN > ");Serial.println(input);
  }

  if (radio.receiveDone())
  {
    for (byte i = 0; i < radio.DATALEN; i++)
      Serial.print((char)radio.DATA[i]);
   
    if (radio.ACK_REQUESTED)
    {
      radio.sendACK();
      Serial.print(" - ACK sent");
    }
   
    Serial.println();
  }
  Blink(LED,5); //heartbeat
}

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




// **********************************************************************************
// This sketch is an example of how wireless programming can be achieved with a Moteino
// that was loaded with a custom 1k bootloader (DualOptiboot) that is capable of loading
// a new sketch from an external SPI flash chip
// The sketch includes logic to receive the new sketch 'over-the-air' and store it in
// the FLASH chip, then restart the Moteino so the bootloader can continue the job of
// actually reflashing the internal flash memory from the external FLASH memory chip flash image
// The handshake protocol that receives the sketch wirelessly by means of the RFM69 radio
// is handled by the SPIFLash/WirelessHEX69 library, which also relies on the RFM69 library
// These libraries and custom 1k Optiboot bootloader are at: http://github.com/lowpowerlab
// **********************************************************************************
// Copyright Felix Rusu, LowPowerLab.com
// Library and code by Felix Rusu - [email protected]
// **********************************************************************************
// License
// **********************************************************************************
// This program is free software; you can redistribute it
// and/or modify it under the terms of the GNU General   
// Public License as published by the Free Software       
// Foundation; either version 3 of the License, or       
// (at your option) any later version.                   
//                                                       
// This program is distributed in the hope that it will   
// be useful, but WITHOUT ANY WARRANTY; without even the 
// implied warranty of MERCHANTABILITY or FITNESS FOR A   
// PARTICULAR PURPOSE. See the GNU General Public       
// License for more details.                             
//                                                       
// You should have received a copy of the GNU General   
// Public License along with this program.
// If not, see <http://www.gnu.org/licenses/>.
//                                                       
// Licence can be viewed at                               
// http://www.gnu.org/licenses/gpl-3.0.txt
//
// Please maintain this license information along with authorship
// and copyright notices in any redistribution of this code
// **********************************************************************************
#include <RFM69.h>         //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>
#include <SPIFlash.h>      //get it here: https://www.github.com/lowpowerlab/spiflash
#include <avr/wdt.h>
#include <WirelessHEX69.h> //get it here: https://github.com/LowPowerLab/WirelessProgramming/tree/master/WirelessHEX69

#define NODEID        4    //unique for each node on same network
#define NETWORKID     100  //the same on all nodes that talk to each other
//#define GATEWAYID     1
#define ENCRYPTKEY    "xxxxxxxxxxxxxxxx" // xed out for forum: exactly the same 16 characters/bytes on all nodes!
#define FREQUENCY     RF69_915MHZ
//#define IS_RFM69HW  //uncomment only for RFM69HW! Leave out if you have RFM69W!
#define SERIAL_BAUD 115200
#define ACK_TIME    30  // # of ms to wait for an ack
#define BLINKPERIOD 500

#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 hsave LEDs on D9
  #define FLASH_SS      8 // and FLASH SS on D8
#endif

RFM69 radio;
char input = 0;
long lastPeriod = -1;

/////////////////////////////////////////////////////////////////////////////
// flash(SPI_CS, MANUFACTURER_ID)
// SPI_CS          - CS pin attached to SPI flash chip (8 in case of Moteino)
// MANUFACTURER_ID - OPTIONAL, 0x1F44 for adesto(ex atmel) 4mbit flash
//                             0xEF30 for windbond 4mbit flash
//                             0xEF40 for windbond 16/64mbit flash
/////////////////////////////////////////////////////////////////////////////
SPIFlash flash(FLASH_SS, 0xEF30); //EF30 for windbond 4mbit flash

void setup(){
  pinMode(LED, OUTPUT);
  Serial.begin(SERIAL_BAUD);
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  radio.encrypt(ENCRYPTKEY); //OPTIONAL
#ifdef IS_RFM69HW
  radio.setHighPower(); //only for RFM69HW!
#endif
  Serial.print("Start node...djashwp-node");
     Serial.println("Sketch is WirelessProgramming_NodeTestNode4-110516");
    Serial.print("Node ");
    Serial.println(NODEID);
    Serial.print("NetworkID ");
    Serial.println(NETWORKID);
  if (flash.initialize())
      Serial.println("SPI Flash Init OK!");
        else
    Serial.println("SPI Flash Init FAIL!");
}

void loop(){
  // This part is optional, useful for some debugging.
  // Handle serial input (to allow basic DEBUGGING of FLASH chip)
  // ie: display first 256 bytes in FLASH, erase chip, write bytes at first 10 positions, etc
  if (Serial.available() > 0) {
    input = Serial.read();
    if (input == 'd') //d=dump first page
    {
      Serial.println("Flash content:");
      int counter = 0;

      while(counter<=256){
        Serial.print(flash.readByte(counter++), HEX);
        Serial.print('.');
      }
     
      Serial.println();
    }
    else if (input == 'e')
    {
      Serial.print("Erasing Flash chip ... ");
      flash.chipErase();
      while(flash.busy());
      Serial.println("DONE");
    }
    else if (input == 'i')
    {
      Serial.print("DeviceID: ");
      Serial.println(flash.readDeviceId(), HEX);
    }
    else if (input == 'r')
    {
      Serial.print("Rebooting");
      resetUsingWatchdog(true);
    }
    else if (input == 'R')
    {
      Serial.print("RFM69 registers:");
      radio.readAllRegs();
    }
    else if (input >= 48 && input <= 57) //0-9
    {
      Serial.print("\nWriteByte("); Serial.print(input); Serial.print(")");
      flash.writeByte(input-48, millis()%2 ? 0xaa : 0xbb);
    }
  }
 
  // Check for existing RF data, potentially for a new sketch wireless upload
  // For this to work this check has to be done often enough to be
  // picked up when a GATEWAY is trying hard to reach this node for a new sketch wireless upload
  if (radio.receiveDone())
  {
    Serial.print("Got [");
    Serial.print(radio.SENDERID);
    Serial.print(':');
    Serial.print(radio.DATALEN);
    Serial.print("] > ");
    for (byte i = 0; i < radio.DATALEN; i++)
      Serial.print((char)radio.DATA[i], HEX);
    Serial.println();
    CheckForWirelessHEX(radio, flash, true);
    Serial.println();
  }
  //else Serial.print('.');
 
  ////////////////////////////////////////////////////////////////////////////////////////////
  // Real sketch code here, let's blink the onboard LED
  if ((int)(millis()/BLINKPERIOD) > lastPeriod)
  {
    lastPeriod++;
    digitalWrite(LED, lastPeriod%2);
  }
  ////////////////////////////////////////////////////////////////////////////////////////////
}
Title: Re: Wireless Programming Handshake Fail
Post by: Felix on November 14, 2016, 10:41:36 AM
Do you have an imperative need to use the old python script?
That's outdated and will not work with the latest libs and sketched. For that purpose I have released a windows GUI to work with.
Title: Re: Wireless Programming Handshake Fail
Post by: djash40 on November 15, 2016, 06:24:27 AM
No, I don't have windows except in a virtual machine. Is there any way I can use linux perhaps with an older script or something or an older version of python?
Title: Re: Wireless Programming Handshake Fail
Post by: Felix on November 15, 2016, 07:47:05 AM
Maybe get an older commit of the WirelessHEX69 lib, not sure which that is but I would look at the timestamps for the python script itself.
Title: Re: Wireless Programming Handshake Fail
Post by: MPParsley on November 25, 2016, 05:12:12 PM
Does this mean that I can't use the python script for linux wireless programming?
Title: Re: Wireless Programming Handshake Fail
Post by: ieris on November 26, 2016, 07:26:03 AM
I have noticed the same problem. Going to deal with it in near future.

EDIT: I can confirm that python script works without any modifications. My problem was in sketch.
Title: Re: Wireless Programming Handshake Fail
Post by: djash40 on December 04, 2016, 03:02:11 PM
I tried a couple older commits of WirelessProgramming.py and still no go in linux.
Does anyone do WP in linux?
I'm using python -V
Python 2.7.12
Title: Re: Wireless Programming Handshake Fail
Post by: Felix on May 25, 2017, 06:49:33 PM
Hey guess what I posted a new OTA.py which is up to date with the protocol. Posted here (https://github.com/LowPowerLab/RFM69/tree/master/Examples/WirelessProgramming_OTA).

So that can be used cross platform.
And also ... WirelessProgramming.exe GUI now includes the option to call that OTA.py script - meaning you can customize it yourself and still use the windows app as a means to pass parameters and watch the stdout output log.

Please try it out and let me know if there's any issues.