LowPowerLab Forum

Software support => Wireless Programming (aka OTA) => Topic started by: Reck_law on August 17, 2014, 05:01:48 PM

Title: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: Reck_law on August 17, 2014, 05:01:48 PM
This page assumes that you already have python and the Arduino ide.

1a:    Download Felix's rfm12b or rfm69, SPIFlash, and WirelessHEX library
      https://github.com/LowPowerLab/RFM69
      https://github.com/LowPowerLab/RFM12B
      https://github.com/LowPowerLab/SPIFlash
      https://github.com/LowPowerLab/WirelessProgramming/tree/master/WirelessHEX
      https://github.com/LowPowerLab/WirelessProgramming/tree/master/WirelessHEX69

1b:   use Felix's example code for wirelessprogramming_gateway and wirelessprogramming_node to start.  Found in his examples directory

2:   Download Felix's python script wirelessprogramming.py
      https://github.com/LowPowerLab/WirelessProgramming

3a:   locate your hex file. I found this at
http://electronics.stackexchange.com/questions/16321/creating-a-sketch-hex-file-from-a-pde-file
I just tried a build and the .HEX file was created in a directory called build2849146248544311107.tmp inside my Temp directory (C:\Users\USERNAME\AppData\Local\Temp\ on Windows 7). Presumably the numbers in the build2849146248544311107.tmp directory name will change. 
Use file xxx.cpp.hex.  Double check with date time stamp

3b:   Copy your hex file to the same directory as wirelessprogramming.py. 

4:   Bring up a command prompt.  Cd to the directory with both the python script and your .cpp.hex file.
Type : where xx is the target moteino,  yyy.cpp.hex is your hex file and comzz is your serial port.
   
Python wirelessprogramming.py –t xx –f yyy.cpp.hex –s comzz
----

Mistakes that I made so you don't have to

Make sure that your gateway node is identified the same in both your gateway and your target.

You probably should put both the node id and code revision in your codes name (so you know what you should be targeting).

You might want to have some way in your code to identify that your code on the target is what
your want it to be (IE I wrote to the wrong moteino so I had two with the same address oops)

please correct any mistakes I have made or any hints that you have to ease the process or if you have done it on another OS.
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: Antony on September 30, 2014, 06:06:40 PM
And in case it helps others, I'll add what helped me get wireless programming going flawlessly on Linux and OS X:
- upgrade to Felix's latest (~Sept 2014) version of RFM69, or equivalent library for your particular moteino;
- look through your gateway's and nodes' codes and replace the deprecated radio.ACK_REQUESTED variable with radio.ACKRequested() method. (My handshake didn't work until both my node and gateway code were updated.)
- ensure you have CheckForWirelessHEX(radio, flash, true) within radio.receiveDone() in your node's loop() method. Without it your node is unable to listen out for the wireless programming handshake from the gateway.
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: hallonstedt on October 01, 2014, 06:00:53 PM
Thank you for the radio.ACKrequested() tip. The FLX? handshake errors were driving me nuts.

For those of you looking for that hex-file; In the Arduino IDE, open File / Preferences. Check the "Show verbose output during: compilation." - Now you will see the hex-file name on the last row in the compiler output. It can be copied and pasted to the python program.

Now that I successfully uploaded a sketch wirelessly (although WirelessProgramming.py tells me IMG was refused by target) I find myself still somewhat confused; How do I force the Moteino back to "node mode" so that I can make another change to the actual sketch running on it and overwrite the old one?

It can't be that I need to upload the node using serial only to upload the sketch I want using wireless so I must be missing something. How does this work with dual boot?
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: Felix on October 01, 2014, 09:08:07 PM
Did you read Antony's points?

Quote- ensure you have CheckForWirelessHEX(radio, flash, true) within radio.receiveDone() in your node's loop() method. Without it your node is unable to listen out for the wireless programming handshake from the gateway.

You can upload ANY sketch via serial. But to upload as sketch wirelessly: your previously uploaded sketch (either first time via serial or Nth time wirelessly) will need to have the CheckForWirelessHEX() call as mentioned above.
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: hallonstedt on October 02, 2014, 02:47:59 PM
Quote from: Felix on October 01, 2014, 09:08:07 PM
Did you read Antony's points?

Thanks Felix. I did read it and I apologize for asking questions that may seem obvious to most on this forum. I have very limited programming experience and used your example node sketch that at first glance looked significantly more complex than just this function.

You'd be surprised how much functionality can be programmed using nothing but other people's code and Googled syntax. It does leave some gaps here and there though.  :D
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: Ric on October 15, 2014, 08:08:01 PM
Thanks for the breakdown Reck_Law! I performed all the steps but unfortunately still can't run the Python script. I renamed the file WirelessProgramming.py to just WP.py and I'm getting this error:


Traceback (most recent call last):
  File"WP.py", line 18, in (module)
    import tyme, sys, serial
ImportError: No module named serial


This happens even when I run "Python WP.py ?"

I installed Python 2.7.3 and got the same message. I made sure that I got the latest WirelessProgramming.py file from Felix's GitHub and installed the newest libraries as well.

Any ideas where I"m failing? I really want to install my SwitchMote on the wall but I don't want to do it until I am able to test this correctly.

Thanks,
Ric
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: Felix on October 16, 2014, 12:11:33 PM
You are missing pyserial.
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: Ric on October 16, 2014, 02:30:58 PM
It works! Thanks ;D  Felix.
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: K1JOS on October 28, 2014, 09:43:07 PM
I want to add this capability to my project.  After browsing the examples and the Python script, it seems the key aspect is make sure to have in my node Loop() the line: "CheckForWirelessHEX(radio, flash, true)"  How much delay does this command introduce into the Loop? 

My remote MegaMoteino already has some heavy time sensitive functions in my Loop() and I am afraid that adding one thing more into the loop such as the "CheckForWirelessHEX(radio, flash, true)" may cause problems.  Right now I send commands from my Gateway to the remote node and the remote manages each command through a list of subroutines :

And I still want to add a temp sensor for frequency correction !!

Since I use a command structure to select various functions for the node Moteino, could i instead have a command that would then call a subroutine like:


void FlashCommand_Rcvd()
{
  if (radio.receiveDone())
  {
    CheckForWirelessHEX(radio, flash, true);
  }
   
  // when done reset
   resetUsingWatchdog(true);
}


I need my Gateway Moteino therefore to use my project's specific data packet structure and specific command code to send to the node to activate the Flash subroutine.  I don't know Python and I am just getting comfortable as a advanced beginner in Arduino C.   Is there any way using the Arduino IDE and/or other libraries to add code to my Gateway program to allow me to open the a HEX file from my PC and send it byte by byte to the node? 

Jerry

Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: Felix on October 29, 2014, 08:52:22 AM
CheckForWirelessHEX needs to be called after receiveDone() and before you clear the radio.DATA buffer or send anything (which will also clear the buffer).
The function simply checks if the last received message has the wireless programming "signature" handshake. If it does, it will start the wireless programming sequence and restart the MCU via watchdog so you don't need to include anything else.
If the signature is not detected it will exit and your code will continue.
In your sample code you should NOT include the resetUsingWatchdog(). That will execute regardless if CheckForWirelessHEX() runs or not.
It does not add significant delay, except obviously when the wireless programming starts to run, that will interrupt any normal code that was running.
The code is in here, quite easy to follow: https://github.com/LowPowerLab/WirelessProgramming/tree/master/WirelessHEX69
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: K1JOS on October 29, 2014, 09:41:37 AM
Thanks Felix, So it sounds real easy on the node side to implement this.  I will pop it into my current node Loop() after radioreceive and see if it causes any functional delays. 
jerry
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: greg on April 06, 2015, 05:44:38 PM
Learn from my mistakes too... make sure you have python 2 not 3.
if you send a sketch successfully, just hangs after it receives it, make sure
you add moteino and mega support into arduino ide:
https://github.com/LowPowerLab/Moteino/tree/master/MEGA/Core
compile with correct board and this stuff really works slick.
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: ivars211 on May 03, 2015, 01:35:25 PM
Another advice - when you are trying to integrate wireless programming in existing software - check that EncryptKey is the same as yours, because I spent an hour trying to figure out, why it doesn't work and the problem was the inconsistency in the keys - in the node-getway the KEY is "thisIsEncryptKey", but in wireless programming example: "sampleEncryptKey".
It would really help if all of the examples would be consistent, you know :d
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: jarrods on May 10, 2015, 06:17:54 AM
Quote from: ivars211 on May 03, 2015, 01:35:25 PM
Another advice - when you are trying to integrate wireless programming in existing software - check that EncryptKey is the same as yours, because I spent an hour trying to figure out, why it doesn't work and the problem was the inconsistency in the keys - in the node-ge[vimeo][/vimeo]tway the KEY is "thisIsEncryptKey", but in wireless programming example: "sampleEncryptKey".
It would really help if all of the examples would be consistent, you know :d

All this code is in the LPL Git Repo https://github.com/LowPowerLab/RFM69/tree/master/Examples (https://github.com/LowPowerLab/RFM69/tree/master/Examples). Your welcome to submit a pull request fixing this. Great way to help out Felix for all the fine work he has done.
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: Felix on May 11, 2015, 08:32:37 AM
Quote from: ivars211 on May 03, 2015, 01:35:25 PM
in the node-getway the KEY is "thisIsEncryptKey", but in wireless programming example: "sampleEncryptKey".
It would really help if all of the examples would be consistent, you know :d

Can you please point me where the inconsistency is (ie provide links)?
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: ivars211 on May 11, 2015, 08:45:23 AM
@ https://github.com/LowPowerLab/RFM69/blob/master/Examples/WirelessProgramming_node/WirelessProgramming_node.ino the key is "sampleEncryptKey", but in
@ https://github.com/LowPowerLab/RFM69/blob/master/Examples/Struct_send/Struct_send.ino the key is "thisIsEncryptKey" :)
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: Felix on May 11, 2015, 08:51:37 AM
Thanks, fixed.
As a rule of thumb you should not assume that all the examples have the same settings.
It's recommended to always double check and adapt the settings to match your hardware and network settings.
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: daemach on June 01, 2015, 06:56:21 PM
I'm trying this and getting the following error:

C:\Users\Daemach\AppData\Local\Temp\build890821271615112406.tmp>C:\Python34\Python.exe wirelessprogramming.py -t 101 -f C:\Users\Daemach\AppData\Local\Temp\build890821271615112406.tmp\SoilNode_v6.cpp.hex" -s com04

  File "wirelessprogramming.py", line 57
    print " -f or -file          HEX file to upload (Default: ", HEX, ")"
                                                              ^
SyntaxError: invalid syntax

C:\Users\Daemach\AppData\Local\Temp\build890821271615112406.tmp>
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: Felix on June 02, 2015, 07:48:06 AM
You need python 2.7
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: pipegf88 on June 05, 2015, 03:12:52 PM
Hi. For those out there who still have the problem, this video explains it clearly:

http://lowpowerlab.com/moteino/#wirelessprogramming (http://lowpowerlab.com/moteino/#wirelessprogramming)

The main problem is to find the .HEX file that is created by the Arduino IDE.

For Windows, follow: https://www.youtube.com/watch?v=cPXO8CbYlKw&feature=youtu.be (https://www.youtube.com/watch?v=cPXO8CbYlKw&feature=youtu.be)

For Mac OS, open the terminal, and type echo $TMPDIR   then you should see the temporary file directory path. Copy the path, then go to the finder window, and press COMMAND + SHIFT + G. A small popup window will appear, where you will copy the path, then it should take you to the temporary folder. Save this folder in your favorites bar, because you will need the .HEX file everytime you want to program the node wireless.

The python software is compatible with OSX too.

Hope that helps you.
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: E.Walker on June 26, 2015, 03:51:23 AM
Hello Guys,

I am playing with my switchmote x2 and a motenio USB, can get the wire less programming working.

On the switchmote, as soon as I put flash.initialize() the radio do not work anymore.

I went on tryin the lib example and it is the same, the python script can't get an answer from the switchmote.

Every thing else is working as intended.

What I tried :

- Download the latest RFM69
- Go to python 2.7 with the serial module
- comment (flash.initialize()) in my original program and the radio work again.
- Try the test program for wirelessprog

Any thought ?

Best regards
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: Felix on June 26, 2015, 08:27:37 AM
What Moteino is installed in the SwitchMote? Do you have the FLASH MEM chip on that Moteino?
What are you using the MoteinoUSB for, the programmer?
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: E.Walker on June 26, 2015, 12:13:00 PM
In the switchmote I have the moteino with the flash chip (the that came with the mote). It the only one I have with the chip.
During setup I get the "SPI Flash Init OK!"

I tried either the switchmote powered by my USB / Serial programmer or directly plug to the 220ac with no difference.

I use SPIFlash flash(8, 0xEF30); //EF30 for windbond 4mbit flash
Maybe I'm wrong with the windbond ?

The other is a motenio USB and wired to my computer for the wireless programming. I puted the example programming gateway in the moteino USB.

Thank for the support

edit : the chip on the switchmote W25X40CLSNIG
W25X40CL(4M-bit) Serial Flash memories
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: E.Walker on June 26, 2015, 12:52:35 PM
I need to invistigate, something is not right

This do not block the radio

flash.initialize();

This block the radio

if (flash.initialize())
Serial.println("SPI Flash Init OK!");
else
Serial.println("SPI Flash Init FAIL!");

I will keep invistigating my code

But still no handshake
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: Felix on June 26, 2015, 01:29:39 PM
Ok so for WP you only need the FLASH MEM in the switchmote, so you're good.
Please ensure you got the latest libs from github.

Also there's a really nice walkthrough by Luis shown on this page (https://lowpowerlab.com/moteino/#wirelessprogramming), maybe worth checking out. I have other videos on the topic and posts on the blog, see this link for those (https://lowpowerlab.com/blog/category/moteino/wireless-programming/).
Title: Re: Wireless Programming 101 (or learn from my mistakes :) - (windows)
Post by: E.Walker on June 26, 2015, 01:52:11 PM
ok, it seems to be working now

My mistakes !

=> not being able to read => "//(16 bytes of your choice - keep the same on all encrypted nodes)"
=> get the latest SPIFlash lib
=> change a little bit my code

  if ( radio.receiveDone() ) {

    CheckForWirelessHEX(radio, flash, true);
   
    if (radio.ACKRequested()) {
      radio.sendACK();
      Serial.print(" - ACK sent");
      delay(10);
    }
   
    demande_radio = *(CDE_salon*)radio.DATA;

Thanks !