Skip to content

Commit

Permalink
Fix OTA & Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
LowPowerLab committed Aug 26, 2019
1 parent 4a6f77a commit e32fc8e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
11 changes: 2 additions & 9 deletions Examples/WirelessProgramming_OTA/Programmer/Programmer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#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://www.github.com/lowpowerlab/spiflash
#include <SPI.h> //included with Arduino IDE (www.arduino.cc)

//****************************************************************************************************************
Expand All @@ -47,7 +46,7 @@
//#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ
#define FREQUENCY RF69_915MHZ
#define FREQUENCY_EXACT 916000000
#define FREQUENCY_EXACT 917000000
#define ENCRYPTKEY "sampleEncryptKey" //(16 bytes of your choice - keep the same on all encrypted nodes)
#define IS_RFM69HW_HCW //uncomment only for RFM69HW/HCW! Leave out if you have RFM69W/CW!
//*********************************************************************************************
Expand All @@ -61,12 +60,6 @@
#define ACK_TIME 50 // # of ms to wait for an ack
#define TIMEOUT 3000

#ifdef __AVR_ATmega1284P__
#define LED 15 // MoteinoMEGA has LED on D15
#else
#define LED 9 // Moteino has LED on D9
#endif

#ifdef ENABLE_ATC
RFM69_ATC radio;
#else
Expand Down Expand Up @@ -152,7 +145,7 @@ void loop(){

Serial.println();
}
Blink(LED,5); //heartbeat
Blink(LED_BUILTIN,1); //heartbeat
}

void Blink(byte PIN, int DELAY_MS)
Expand Down
41 changes: 26 additions & 15 deletions Examples/WirelessProgramming_OTA/Target/Target.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,27 @@
//****************************************************************************************************************
//**** IMPORTANT RADIO SETTINGS - YOU MUST CHANGE/CONFIGURE TO MATCH YOUR HARDWARE TRANSCEIVER CONFIGURATION! ****
//****************************************************************************************************************
#define NODEID 123 // node ID used for this unit
#define NETWORKID 100
#define NODEID 123 // node ID used for this unit
#define NETWORKID 100
//Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ
#define FREQUENCY RF69_915MHZ
#define FREQUENCY_EXACT 916000000
#define FREQUENCY_EXACT 917000000
#define ENCRYPTKEY "sampleEncryptKey" //(16 bytes of your choice - keep the same on all encrypted nodes)
#define IS_RFM69HW_HCW //uncomment only for RFM69HW/HCW! Leave out if you have RFM69W/CW!
//*****************************************************************************************************************************
#define ENABLE_ATC //comment out this line to disable AUTO TRANSMISSION CONTROL
#define ATC_RSSI -75
#define ATC_RSSI -80
//*****************************************************************************************************************************
//#define BR_300KBPS //run radio at max rate of 300kbps!
//*****************************************************************************************************************************
#define SERIAL_BAUD 115200
#define ACK_TIME 30 // # of ms to wait for an ack
#define ENCRYPTKEY "sampleEncryptKey" //(16 bytes of your choice - keep the same on all encrypted nodes)
#define BLINKPERIOD 500
#define BLINKPERIOD 200

#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
#if defined(MOTEINO_M0) && defined(SERIAL_PORT_USBVIRTUAL)
#define Serial SERIAL_PORT_USBVIRTUAL // Required for Serial on Zero based boards
#endif

#ifdef ENABLE_ATC
Expand All @@ -82,12 +78,14 @@ long lastPeriod = -1;
// MANUFACTURER_ID - OPTIONAL, 0x1F44 for adesto(ex atmel) 4mbit flash
// 0xEF30 for windbond 4mbit flash
// 0xEF40 for windbond 16/64mbit flash
// 0x1F84 for adesto 4mbit AT25SF041 4MBIT flash
//*****************************************************************************************************************************
SPIFlash flash(FLASH_SS, 0xEF30); //EF30 for windbond 4mbit flash
SPIFlash flash(SS_FLASHMEM, 0xEF30); //EF30 for windbond 4mbit flash

void setup() {
pinMode(LED, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(SERIAL_BAUD);
delay(1000);
radio.initialize(FREQUENCY,NODEID,NETWORKID);
radio.encrypt(ENCRYPTKEY); //OPTIONAL

Expand All @@ -102,7 +100,7 @@ void setup() {
#ifdef IS_RFM69HW_HCW
radio.setHighPower(); //must include this only for RFM69HW/HCW!
#endif
Serial.print("Start node...");
Serial.println("Start node...");
Serial.print("Node ID = ");
Serial.println(NODEID);

Expand Down Expand Up @@ -140,6 +138,18 @@ void loop(){

Serial.println();
}
else if (input == 'D') //d=dump higher memory
{
Serial.println("Flash content:");
uint16_t counter = 4090; //dump the memory between the first 4K and second 4K sectors

while(counter<=4200){
Serial.print(flash.readByte(counter++), HEX);
Serial.print('.');
}

Serial.println();
}
else if (input == 'e')
{
Serial.print("Erasing Flash chip ... ");
Expand Down Expand Up @@ -193,6 +203,7 @@ void loop(){
{
lastPeriod++;
digitalWrite(LED, lastPeriod%2);
Serial.print("BLINKPERIOD ");Serial.println(BLINKPERIOD);
}
//*****************************************************************************************************************************
}
10 changes: 5 additions & 5 deletions RFM69_OTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <avr/wdt.h>
#endif

#ifdef MOTEINO_ZERO
#ifdef MOTEINO_M0
#if defined(SERIAL_PORT_USBVIRTUAL)
#define Serial SERIAL_PORT_USBVIRTUAL // output on SerialUSB instead of Serial
#endif
Expand Down Expand Up @@ -130,7 +130,7 @@ uint8_t HandleWirelessHEXData(RFM69& radio, uint8_t remoteID, SPIFlash& flash, u
//first clear the fist 32k block (dedicated to a new FLASH image)
flash.blockErase32K(0);
flash.writeBytes(0,"FLXIMG:", 7);
#if defined (MOTEINO_ZERO)
#if defined (MOTEINO_M0)
flash.writeByte(10,':');
uint32_t bytesFlashed=11;
#else
Expand Down Expand Up @@ -211,7 +211,7 @@ uint8_t HandleWirelessHEXData(RFM69& radio, uint8_t remoteID, SPIFlash& flash, u
if (dataLen==7 && radio.DATA[4]=='E' && radio.DATA[5]=='O' && radio.DATA[6]=='F') //Expected EOF
{

#if defined (MOTEINO_ZERO)
#if defined (MOTEINO_M0)
if ((bytesFlashed-10)>253952) { //max 65536 - 10 bytes (signature)
if (DEBUG) Serial.println(F("IMG > 64k, too big"));
radio.sendACK("FLX?NOK:HEX>64k",15);
Expand All @@ -233,7 +233,7 @@ uint8_t HandleWirelessHEXData(RFM69& radio, uint8_t remoteID, SPIFlash& flash, u
HandleHandshakeACK(radio, flash, false);
if (DEBUG) Serial.println(F("FLX?OK"));
//save # of bytes written
#ifdef MOTEINO_ZERO
#ifdef MOTEINO_M0
flash.writeByte(7,(bytesFlashed-11)>>16);
flash.writeByte(8,(bytesFlashed-11)>>8);
flash.writeByte(9,(bytesFlashed-11));
Expand Down Expand Up @@ -545,7 +545,7 @@ void resetUsingWatchdog(uint8_t DEBUG)
if (DEBUG) Serial.print(F("REBOOTING"));
wdt_enable(WDTO_15MS);
while(1) if (DEBUG) Serial.print(F("."));
#elif defined(MOTEINO_ZERO)
#elif defined(MOTEINO_M0)
WDT->CTRL.reg = 0; // disable watchdog
while (WDT->STATUS.bit.SYNCBUSY == 1); // sync is required
WDT->CONFIG.reg = 0; // see Table 18.8.2 Timeout Period (valid values 0-11)
Expand Down
2 changes: 1 addition & 1 deletion RFM69_OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <RFM69.h>
#include <SPIFlash.h>

#if defined(MOTEINO_ZERO)
#if defined(MOTEINO_M0)
#define LED 13 // Moteino M0
#elif defined(__AVR_ATmega1284P__)
#define LED 15 // Moteino MEGAs have LEDs on D15
Expand Down

0 comments on commit e32fc8e

Please sign in to comment.