All posts by Per Magnusson

Problems with Python XBee 2.2.3 package

This blog post describes an issue I am having with the XBee 2.2.3 Python package where the callbacks that are supposed to happen when new packets are received suddenly stop. I managed to find the reason for this as well as an at least temporary solution.

A bit of background

I just tried to add a second node to my small ZigBee network (now consisting of a coordinator and two routers) and ran into a bit of trouble. The new node has a new version of the XBee radio, namely XB24CZ7PIT-004. This has replaced the previous product XB24-ZB from Digi and it has a new firmware which simultaneously supports coordinator/router/end point. So one does not have to upload a firmware specific to the role the radio is playing in the network. Maybe it has other subtle differences as well. I do not know if the new radio version is relevant to the problems I am having, but I thought I’d better mention it.

The problem

I use a callback function to receive the data from the XBee, but the problem is that when I added the new XBee (as a router), I just got one or a few packets back from the coordinator (which is the one I talk to using Python) before callbacks stopped. I discovered that a new error callback feature had been added in 2.2.2, so I made use of this to try to troubleshoot:

 # Callback function that runs when XBee errors are detected
 def xbee_error(e):
     print "XBee error!"
     print e
 
 xbee = ZigBee(ser, callback = receive_data, error_callback = xbee_error)

 

This gave me the following printout before receive_data callbacks ceased:

XBee error!
'Unrecognized response packet with id byte \xa1'

So apparently a “new” kind of packet with frame type A1 has started to show up for some reason unknown to me. This turns out to be a “Route Record Indicator”. I have not looked into why this happens, but since the A1 frame type is not defined in the api_responses dictionary in zigbee.py and there is a new except-clause with a break in the definition of run() in base.py, I think the thread that receives data from the XBee and calls the callback function thereby terminates when such an unrecognized frame id is received.

I do not think this is appropriate behavior in this case. The thread should not die just because an A1 frame ID appears. I solved it quickly and in an ugly manner by commenting out the troublesome break in base.py:

    def run(self):
         """
         run: None -> None
 
         This method overrides threading.Thread.run() and is automatically
         called when an instance is created with threading enabled.
         """
         while True:
             try:
                 self._callback(self.wait_read_frame())
             except ThreadQuitException:
                 # Expected termintation of thread due to self.halt()
                 break
             except Exception as e:
                 # Unexpected thread quit.
                 if self._error_callback:
                     self._error_callback(e)
                 <b>#break # Commented out by Per M 2016-01-06</b>

There are probably better ways to solve this. Maybe the A1 and other possible frame IDs (see the API frame specifications section in the XBee User Guide) should be added to api_responses in zigbee.py.

Making VLC automatically reload the favorite playlist

I sometimes use VLC as an mp3 player and it would be nice if it did automatically load my default playlist when it starts. It is not apparent from the settings within VLC how to accomplish this, but some googling brought up an old blog post from 2007 that explained how to do it. Sort of. The information was outdated, but the remaining piece of the puzzle was provided in one of the comments.

This is how to make VLC automatically load a specific playlist:

  • Select the menu Tools->Settings.
  • Click to show all settings and not just the simple ones.
  • Click on playlist.
  • Fill out the path to the playlist in the field “Standard stream”: file:///C:/audio_files/playlist.m3u
  • Click Save.

Note that there shall be three slashes after file: and that the slashes shall be forward (/), not backward (\) as is usually the case in file paths on Windows.

 

Changing to mbed firmware on FRDM-KL25Z using Windows 10

I have a couple of projects where I want to use the ARM mbed platform on the inexpensive  FRDM-KL25Z board, which features the Freescale Kinetis KL25Z ARM Cortex-M0+ processor. This requires a firmware update on the board and I have done this previously without trouble while I was still running Windows 7. Now however, I have moved to Windows 10 and this caused a bit of trouble.

This post describes the problems I ran into and how I solved them. In essence, I was forced to use a computer running Windows 7 to do the actual update.

Failed attempt

The firmware upgrade process is described on this page. While there are some hints on that page that the upgrade might not work if the host computer runs Windows 8 or Windows 10, this is not entirely clear, so I tried it anyway. This is what I did and what happened:

  • Download the 20140530_k20dx128_kl25z_if_opensda firmware file (a zipped .s19 file) and unzip it.
  • Hold down the reset button on the FRDM-KL25Z board while plugging in the USB cable in the right (SDA) USB connector.
  • The board now appears as a disk called BOOTLOADER.
  • Drag the .s19 file to the BOOTLOADER disk.
  • Unplug and replug the FRDM-KL25Z.
  • If everything had worked as it should, the board would now have shown up as a disk called MBED. What instead happened was that the computer did not at all react to the board. No disk showed up.

Reading a bit more on the firmware upgrade page and in the discussions at the bottom of the page, it seemed like there was no way forward using only a Windows 10 computer.

Successful attempt

The reason it did not work with Windows 10 seems to be that my FRDM-KL25Z board had too old bootloader firmware. It has to be 1.11 or higher to work on Windows 10 (or Linux and Mac it seems). To check the bootloader version, one can hold down the reset button while plugging in the USB cable into the SDA port. This makes the board show up as a BOOTLOADER disk where there is a file called SDA_INFO.HTM. Double clicking on this file brings up a web page that says among other things what the bootloader version is. In my case it was 1.09.

To remedy this, the following steps are required:

  • Get hold of a computer running Windows 7 or Windows  XP.
  • Hold down the reset button on the FRDM-KL25Z board while plugging in the USB cable in the right (SDA) USB connector.
  • The board now appears as a disk called BOOTLOADER.
  • Download a new OpenSDA bootloader firmware from PE Micro. This requires some form of registration and giving out an email address, but is otherwise free.
  • Unzip the downloaded file.
  • Unzip the OpenSDA_Bootloader_Update_App_v111_2013_12_11.zip (or similar) file from inside the big zip file.
  • Drag and drop the resulting BOOTUPDATEAPP_Pemicro_v111.SDA (or later version) file to the root directory of the BOOTLOADER disk.
  • Unplug and replug the board to initiate the bootloader update. This typically takes just a few seconds.
  • Once the update is complete the board will automatically reappear as a disk called BOOTLOADER.
  • Double click on the SDA_INFO.HTM file in the root directory of the BOOTLOADER disk to see that the bootloader version now is 1.11 (or higher).
  • Drag the 20140530_k20dx128_kl25z_if_opensda.s19 (or whatever the latest version of the mbed firmware is) to the BOOTLOADER disk.
  • Unplug and replug the board. It should now show up as a disk called MBED.

After this, the board showed up as a disk called MBED and worked on Windows 10.

To upload and run a .bin-file (the output of the mbed online compiler) to the board one drags the .bin file to the MBED drive and then presses reset on the KL25Z board.