This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2530: Change from end device to router

Part Number: CC2530
Other Parts Discussed in Thread: Z-STACK

Hi,

I'm trying to build a device so that when it is battery powered, it will send a signal to the CC2530 telling that it is an end device. And when it is powered from an outlet, it will tell the CC2530 to be a router. Using SampleLight, how can I make it so when the CC2530 receives a signal, it can flip from an end device to a router and vice versa?

  • You can try to use ZAP-ZNP mode to achieve this.

  • How do I use ZAP-ZNP mode?
  • You have to use an extra MCU to act as ZAP and CC2530 as ZNP. You can refer to Z-Stack ZNP Interface Specification.pdf in Z-Stack document folder for details.
  • Why can't all this be done using only 1 MCU?
  • Everything is possible. You can try to run ZAP-ZNP on single MCU.
  • Hi,

    In the out of box sample applications, run-time logical device type configuration is only available if the CC2530 is running the ZNP application. It may be possible to design your own logic in your application to modify the global zgDeviceLogicalType and set it based on the scenario you mention. You can search for this variable in the code to see what is happening but basically zgDeviceLogicalType needs to be set before you start network formation/joining (i.e. before ZDOInitDeviceEx() is called).

    I can't guarantee this will work nicely because it hasn't been tested, but it is a starting point. I'd recommend you start with the Router build configuration in IAR and then add your logic into the sample application from there.
  • Sorry for any confusion, but perhaps I may have explained this incorrectly. I want the CC2530 to flip from and end device to a router which acts like a end device (not a ZNP). So this way it can pass messages along from 1 device to the next. I'm not trying to start a new network when turned into a router config. So how can I program the end device config to turn into a router config automatically when the signal is sent to the CC2530?

  • You cannot change role dynamically which would confuse whole mesh network. You should make device leave network first, and turn role to router to do a fresh joining process.
  • ZNP is not a device type, it is comparable to a sample application, like SampleLight. With SampleLight, you can have a device act as an end device, a router, or a coordinator. The difference with ZNP is that when you make a ZNP device on CC2530, you do not have to choose a build configuration at compile-time like you do with SampleLight. You know how in IAR for SampleLight you choose either coordinator, router, or end device before you build your code? You don't have to do that with ZNP, with ZNP you choose the logical device type at run-time (as opposed to compile-time). This is done by setting the value for zgDeviceLogicalType, and then calling the API ZDOInitDeviceEx() which starts network formation/joining (in Z3.0, that API is called by the BDB commissioning API).

    One key point you have to understand about this is that you cannot "switch" device types after you have initialized your device as a single logical type. This is to say, after you set zgDeviceLogicalType for the first time and then initialize your device, you may not switch its type unless you factory reset the device.

    My second point from above is that the sample applications like SampleLight are not designed to be able to configure logical device type at run-time, the sample applications only provide the means to set logical device type at compile-time, i.e. you must configure it in IAR before you build your application. I also mentioned that it may be possible to change it to a run-time configuration, but this is not supported by default in the out-of-box sample applications, you would need to implement it yourself. As for how to do that, refer to my previous post.
  • So I'll probably go with the method of resetting the device before turning into a router config. So when I initially start as an end device config, but then I plug it into the wall outlet, the CC2530 will factory reset and then turn into a router config. I know how to implement the factory reset part, but how can I change the compile option from end device to router from within the code, when the CC2530 receives a signal that it's plugged into the wall? How can I turn the role into a router?

    Also, is the only way to this through a run-time config? Or is there some simple code I can write to do the above questions?

  • Maybe try to manipulate zgDeviceLogicalType in ZDAppDetermineDeviceType().
  • I tried setting zgDeviceLogicalType = ZG_DEVICETYPE_ROUTER in ZMain.c, but it didn't seem to change the config from end device to router. What else do you suggest?
  • You can't start with an end device project and turn it into a router by setting zgDeviceLogicalType to ZG_DEVICETYPE_ROUTER, the code that is required for the device to be a router will not be present in the build.

    You may be able to start with a router project and turn it into an end device though. You may also need to change the libraries that are linked into the build, go to Project Options > Linker > Extra Options and change Router-Pro.lib to AllDevice-Pro.lib. Beyond that, I suggest you look into the ZNP project code to better understand how exactly it is able to have all three device types in one build configuration.
  • 1. What part of the ZNP example code should I start trying to modify to determine whether the CC2530 will be a router or end device?
    2. What function in the ZNP example is similar to the zclSampleLight_UpdateLedState() function from SampleLight Z-Stack 3.0?

  • 1. ZNP contains all ZC/ZR/ZED configuration and it depends on ZAP to assign which role it would run.
    2. zclSampleLight_UpdateLedState is application code and there is no mapping function in ZNP.