OpenThread with Particle.io

340 views
Skip to first unread message

Jeremy Ellis

unread,
Dec 10, 2018, 12:12:02 AM12/10/18
to openthread-users
Has anyone tried using openThread with Particle.io products? They just shipped last week. Lots of potential here for interesting projects. 


Jonathan Hui

unread,
Dec 10, 2018, 12:55:11 PM12/10/18
to keyfre...@gmail.com, openthread-users
Anyone who has played with Particle Mesh devices (especially Xenons) have played with OpenThread, since OpenThread is providing the IPv6 communication technology when communicating over IEEE 802.15.4 radios. If you haven't already, you should also check out community.particle.io to interact directly with the Particle community.

--
Jonathan Hui


On Sun, Dec 9, 2018 at 9:12 PM Jeremy Ellis <keyfre...@gmail.com> wrote:
Has anyone tried using openThread with Particle.io products? They just shipped last week. Lots of potential here for interesting projects. 


--
You received this message because you are subscribed to the Google Groups "openthread-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openthread-use...@googlegroups.com.
To post to this group, send email to openthre...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openthread-users/155cebdc-862c-42a0-81e0-9a89d97cac16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeremy Ellis

unread,
Dec 10, 2018, 6:41:37 PM12/10/18
to openthread-users
My devices work fine with the Particle.io version of OpenThread. I would like to use the devices to setup my own network using my Raspberry Pi3B or linux machine as the border-router. Just wondering if anyone knows the steps involved, or has done it already.

Jonathan Hui

unread,
Dec 11, 2018, 8:12:44 PM12/11/18
to Jeremy Ellis, openthread-users
Particle's version of OpenThread is simply a snapshot of openthread/openthread at a particular commit id.

As a result, it should be possible for Particle.io devices to connect to any other device running OpenThread. That said, I believe Particle has yet to expose the necessary configuration APIs that would make it possible to extract/provide Thread network credentials from/to a Particle device, making it hard to actually attach a Particle device to a non-Particle network. I would reach out to Particle regarding this feature.

--
Jonathan Hui

Jeremy Ellis

unread,
Dec 11, 2018, 8:48:49 PM12/11/18
to openthread-users
Thanks for the reply Jonathan. I have started a topic in the Particle forum.


I hope the Particle API allows us to extract the credentials. I am also hoping Jonathan Beri takes an interest in this as he has done some commits for OpenThread and works for Particle.




Jeremy Ellis

unread,
Dec 21, 2018, 8:44:19 AM12/21/18
to openthread-users
Jonathan, can you help with one more question.


Most setups with OTBR have a USB dongle connected to the border router, and then a cell phone to commission devices, but Particle uses a cloud based system as the border router and then a cell phone to commission the devices.

Has Particle developed a proprietary method to do this or is a cloud based border router something supported by OpenThread?

Jonathan Hui

unread,
Dec 21, 2018, 4:35:02 PM12/21/18
to Jeremy Ellis, openthread-users
Particle currently uses their own method and protocols for adding devices to the Particle Mesh network.

--
Jonathan Hui

--
You received this message because you are subscribed to the Google Groups "openthread-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openthread-use...@googlegroups.com.
To post to this group, send email to openthre...@googlegroups.com.

Jeremy Ellis

unread,
Jan 9, 2019, 7:50:58 PM1/9/19
to openthre...@googlegroups.com
So I got the Particle.io Devices accessing the C code of OpenThread with a proof of concept bit of code:

This code I loaded onto a Particle Gateway (Argon) which was connected to a Particle End Device (Xenon). The Xenon was publishing a message every 30 seconds, using my Hello Mesh Program  

Remember RSSI values of -1 would be a very strong signal and RSSI values of -99 would be very weak.

#include "Particle.h"
// Easiest RSSI test program
// By Jeremy Ellis




#include "ot_api.h"
extern "C" {
 int8_t otPlatRadioGetRssi
(otInstance *aInstance);
};




void setup() {
 
}


void loop() {


  int8_t rssi
= otPlatRadioGetRssi(0);
 
//snprintf(buf, sizeof(buf), “>%d <%d”, (int)rssi, lastRssi);
 
 
Particle.publish("RSSI ", "#" + String(rssi), 60, PRIVATE);  //shows printing an integer variable
 
Particle.publish("----------------","-------------", 60, PRIVATE);    // just to show a space between samples
  delay
(10000); // wait about 10 seconds


}

Here is the output on the Particle Cloud Console.

rssi-movingaway.png



Full blurb about it here 

So now that OpenThread is possible on a Particle Mesh Device, I have a question:

What Objects, Methods and Properties should I try next? I really want to connect a Particle Device to an OpenThread Border Router, does anyone have any suggestions? 

The OpenThread API is here but that is much more information than I need to know. 

I just want basic abilities: 


1. Connect to the Border Router using a serial connection
or
2. Connect to the Commissioning Thread App for a Thread network setup using a Nordic Dongle connected to the Border Router.



Many of the other abilities are pre-compiled into the Particle Devices.


Even a list of commands to look into would be appreciated.

1. otPlatRadioGetRssi(otInstance *aInstance)
2
3
4
5
6
7
8



Jonathan Hui

unread,
Jan 10, 2019, 12:49:01 PM1/10/19
to Jeremy Ellis, openthread-users
For Particle and OTBR to communicate, they need to be configured with the same Thread Network configuration. There are two options:
  1. Configure OTBR to use the Particle device's Thread Network configuration.
  2. Configure Particle device to use OTBR's Thread Network configuration.
I'm not currently familiar with Particle's use of OpenThread. So I'll stick with Option 1 above.

At a minimum, OTBR needs to know the Channel, PAN ID, Thread Master Key, and Network Name to join a network.

To retrieve the Particle device Thread Network configuration, you can use:
  1. otDatasetGetActive() to retrieve all the parameters in one structure, or
  2. otLinkGetChannel()otLinkGetPanId()otThreadGetMasterKey()otThreadGetNetworkName() to retrieve them individually.
With the configuration information in hand, try the following commands on OTBR:

$ wpanctl leave
$ wpanctl join -T r -p <panid> -c <channel> -k <masterkey> -n <networkname>

Hope that helps.

--
Jonathan Hui

2. Add an End Device, 

3. Add a REED (Router Eligible End Device)

Many of the other abilities are pre-compiled into the Particle Devices.


Even a list of commands to look into would be appreciated.

1. otPlatRadioGetRssi(otInstance *aInstance)
2
3
4
5
6
7
8



--
You received this message because you are subscribed to the Google Groups "openthread-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openthread-use...@googlegroups.com.
To post to this group, send email to openthre...@googlegroups.com.

Jeremy Ellis

unread,
Jan 10, 2019, 10:37:48 PM1/10/19
to openthread-users
That info is really useful Jonathon. Thank you very much. I will be googling for links to example code using this information.

Jeremy Ellis

unread,
Jan 14, 2019, 12:24:51 AM1/14/19
to openthread-users
Not finding a lot of example code, but by doing a bit of digging and some trial and error I am getting working code, although I think my output format is wrong for both the otThreadGetMasterKey() and the otThreadGetNetworkName()

Here is my code:

networkNameCode.png



And my output after doing some print statements (Particle.publish(String(),String(),60,Private);) looks like


networkName.png



Fairly sure the NetworkName is a simple string not the mess I am getting, and the Master Key should be much longer (Is it compressed?). Any suggestions?


P.S. Why do I pass (0) to each method? 


Jeremy Ellis

unread,
Jan 14, 2019, 10:07:14 AM1/14/19
to openthread-users
I guess it is more useful if I paste the code

#include "Particle.h"

#include "ot_api.h"
extern "C" {
    
    int8_t    otLinkGetChannel(otInstance *aInstance);
    uint16_t  otLinkGetPanId(otInstance *aInstance);     // type otPanId
    uint8_t   otThreadGetMasterKey(otInstance *aInstance);
    char     *otThreadGetNetworkName(otInstance *aInstance);
    
};


void loop() {
    
   int8_t myChannel = otLinkGetChannel(0);
   uint16_t myPanID = otLinkGetPanId(0);    // otPanId
   
   char myPanIDBuff[255];
   snprintf(myPanIDBuff, sizeof(myPanIDBuff), "0x%X", myPanID);   // put hex into myPanIDBuff
   
   uint8_t myMasterKey = otThreadGetMasterKey(0);
   char *myNetworkName = otThreadGetNetworkName(0);
   
   
   char myNetworkNameBuff[255];
   snprintf(myNetworkNameBuff, sizeof(myNetworkNameBuff), "%s", myNetworkName);   // network name as a string
   

   Particle.publish("----------------","-------------", 60, PRIVATE);    // just to show a space between samples
   delay(2000); 
   Particle.publish("Particle Thread ","Connection Information", 60, PRIVATE);    // just to show a space between samples
   delay(2000); 
   Particle.publish("My Channel: ", String(myChannel), 60, PRIVATE);  //shows printing an integer variable
  
   delay(2000); 
   Particle.publish("Argon Pan ID: ", String(myPanIDBuff), 60, PRIVATE);  //shows printing an integer variable
   delay(2000); 
   
   Particle.publish("My Master Key: ", String(myMasterKey), 60, PRIVATE);  //shows printing an integer variable
   delay(2000); 
   Particle.publish("My Network Name: ", String(myNetworkNameBuff), 60, PRIVATE);  //shows printing an integer variable
   delay(2000); 
   Particle.publish("----------------","-------------", 60, PRIVATE);    // just to show a space between samples
   delay(2000); 
   Particle.publish("Generates the same info","every 60 seconds", 60, PRIVATE);    // just to show a space between samples
 
   delay(60000);  // wait 60 seconds before re-print
}


Jonathan Hui

unread,
Jan 14, 2019, 3:59:38 PM1/14/19
to Jeremy Ellis, openthread-users
For the `aInstance` parameter, you need to pass a valid pointer to an OpenThread instance. Passing 0 is the same as passing NULL. That's why you are seeing strange values for things like Master Key and Network Name.

You'll need to find out how to grab the OpenThread instance pointer from the Particle environment.

--
Jonathan Hui

--
You received this message because you are subscribed to the Google Groups "openthread-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openthread-use...@googlegroups.com.
To post to this group, send email to openthre...@googlegroups.com.

Jeremy Ellis

unread,
Jan 14, 2019, 4:54:37 PM1/14/19
to openthre...@googlegroups.com
Yes. Just figured that out. Getting good values now for the networkname.

Next will try connecting with my border router. May have to get my nrf42840 USB Dongle working first. Not sure if I can connect the particle gateway directly to the border router or if I have to start the thread using the Dongle and then connect the Particle Device to that network.


..

On second look I am having problems with the MasterKey. I get 9 numbers but the Border Router is expecting 32 characters.  Looks like otThreadGetMasterKey() is compressed. Looking for a function to convert the numbers to a character string.  

Found  here

    property String^ MasterKey


and also found but not sure how to use:


void Interpreter::ProcessMasterKey(int argc, char *argv[])



Jeremy Ellis

unread,
Jan 16, 2019, 10:29:37 AM1/16/19
to openthread-users
All good now. Thanks for your help Jonathan.

Jeremy Ellis

unread,
Jan 21, 2019, 11:59:53 PM1/21/19
to openthread-users
Thanks so much Jonathan Hui, this has been quite a challenge.

What I found is potentially working to connect a particle device. (using fake data) 


sudo /usr/local/bin/wpanctl


help


scan


   
| Joinable | NetworkName        | PAN ID | Ch | XPanID           | HWAddr           | RSSI
---+----------+--------------------+--------+----+------------------+------------------+------
 
1 |       NO | "b_group"          | 0x3844 | 11 | C93A555AC477FF4A | 123444F7B9F8D07B |  -64


setprop
NetworkKey --data f73f8a29d093eb1c4d444eb31649a483


join
1


or


join
-T r -p 0x3844 -c 11  -x C93A555AC477FF4A b_group


status


getprop
-a






It does setup the thread but I am presently not sure how usable this thread network is.

Jonathan Hui

unread,
Jan 23, 2019, 1:23:09 PM1/23/19
to Jeremy Ellis, openthread-users
If you run "wpanctl status" and see "NCP:State" as "associated", then the border router has properly attached to the Particle device.

If you perform a "ping6 -Iwpan0 ff02::1", you should see responses from the Particle device.

--
Jonathan Hui

--
You received this message because you are subscribed to the Google Groups "openthread-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openthread-use...@googlegroups.com.
To post to this group, send email to openthre...@googlegroups.com.

Jeremy Ellis

unread,
Mar 14, 2019, 1:30:23 AM3/14/19
to openthread-users
Jonathan Hui


I am back trying to connect a few Particle.io Argon's to an OpenThread network (think of Argon's as Full Thread Device devices FTD). I can connect one Argon with several Xenon's (Xenons are  REED's ) to OpenThread, but will need to set both the NetworkName and MasterKey to be able to connect other Argon's

A while ago you gave me some really useful information with your quote:


At a minimum, OTBR needs to know the Channel, PAN ID, Thread Master Key, and Network Name to join a network.
To retrieve the Particle device Thread Network configuration, you can use:
otDatasetGetActive() to retrieve all the parameters in one structure, or
otLinkGetChannel(), otLinkGetPanId(), otThreadGetMasterKey(), otThreadGetNetworkName() to retrieve them individually.



I used the above information to connect one Argon to openThread, but now would like to connect several Argon's:

I need to be able to set the Masterkey and Network name to be the same as the values extracted from the 
first Argon.  I am fairly close to getting it working, but could
really benefit from some example C++ code showing how to use the API

These links are not much use: 







which shows this code:

  networkName.SetNetworkName(netif.GetMac().GetNetworkName());




and this


which shows this code:

netif.GetKeyManager().SetMasterKey(key->GetNetworkMasterKey());





my programming setup looks like this:

#define OT_MASTER_KEY_SIZE 16


#include "ot_api.h"
#include "openthread/dataset.h"





extern "C" {


    int8_t       otLinkGetChannel
(otInstance *aInstance);
    uint16_t     otLinkGetPanId
(otInstance *aInstance);         // type otPanId

    otMasterKey  
*otThreadGetMasterKey(otInstance *aInstance);

   
char         *otThreadGetNetworkName(otInstance *aInstance);


};


void loop() {



        otInstance
*  ot = ot_get_instance();


        int8_t myChannel
= otLinkGetChannel(ot);
        uint16_t myPanID
= otLinkGetPanId(ot); // otPanId


     
// etc, etc  ...
}






Any suggestions for setting the Particle Argon NetworkName and MasterKey? Do you have any code snippets or even pseudo code that you can write or send, anything you have would be appreciated.






Jeff Bumgardner

unread,
Mar 14, 2019, 9:30:46 AM3/14/19
to Jeremy Ellis, openthread-users
Hey Jeremy, have you checked our API codelab?  It has some code for setting those properties in an otOperationalDataset struct that might be useful:


Jeff

--
You received this message because you are subscribed to the Google Groups "openthread-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openthread-use...@googlegroups.com.
To post to this group, send email to openthre...@googlegroups.com.

Jeremy Ellis

unread,
Mar 14, 2019, 9:41:15 PM3/14/19
to openthread-users
Jeff Bumgardner you are a wonderful person! You just saved me hours of work.

I am sure I could make my own parse function, but someone at OpenThread must have already made a function to convert between the String and the input and also to convert the other way.

/* Set master key to 1234C0DE1AB51234C0DE1AB51234C0DE */
    uint8_t key
[OT_MASTER_KEY_SIZE] = {0x12, 0x34, 0xC0, 0xDE, 0x1A, 0xB5, 0x12, 0x34, 0xC0, 0xDE, 0x1A, 0xB5};

   

Jonathan Hui

unread,
Mar 14, 2019, 10:44:06 PM3/14/19
to Jeremy Ellis, openthread-users
For ascii hex to binary conversion, take a look at Interpreter::Hex2Bin().

--
Jonathan Hui

Jeremy Ellis

unread,
Mar 15, 2019, 2:39:44 AM3/15/19
to openthread-users
Thanks Jonathon.

Jeremy Ellis

unread,
Apr 3, 2019, 11:12:50 PM4/3/19
to openthread-users



Has anyone got a working version of the codelab example at   https://codelabs.developers.google.com/codelabs/openthread-apis/#7  ? I think that the files have changed since the example was made. This following code doesn't make much sense since main.c does not contain otSysButtonInit anymore. 

In main.c, add these function calls to the main() function after the otSysButtonInit call. This function configures the Thread network dataset.

/* Start the Thread network interface (CLI cmd > ifconfig up) */
otIp6SetEnabled(instance, true);

/* Start the Thread stack (CLI cmd > thread start) */
otThreadSetEnabled(instance, true);


Also I can include #include <openthread/dataset_ftd.h>   without an error 
but the following "IF" statement calls a warning. 

#if OPENTHREAD_FTD



Anyone got a github with a working example of the same codelab?

I am trying to get my Particle Mesh Hardware (Argon and Xenon) working with a true OpenThread Border Router, instead of the fancy Particle Cloud Border Router. The Particle devices are based off the Nordic nrf52840 chip but have a few different settings and needs a .bin file instead of a .hex file. (I have tried loading the generated .bin file but that does not seem to work.)

Any suggestions would be appreciated.

Jonathan Hui

unread,
Apr 4, 2019, 12:50:34 AM4/4/19
to Jeremy Ellis, openthread-users
Did you follow the codelab step-by-step? The codelab builds on itself and adding the call to `otSysButtonInit()` is done in a prior step.

In particular, 7. API: Use multicast to turn on an LED includes the following:

ACTION: Add calls to initialize the GPIO LEDs and button

In main.c, add these function calls to the main() function after the otSetStateChangedCallback call. These functions initialize the GPIO and GPIOTE pins and set a button handler to handle button push events.

/* init GPIO LEDs and button */
otSysLedInit();
otSysButtonInit(handleButtonInterrupt);
Hope that helps.

--
Jonathan Hui

--
You received this message because you are subscribed to the Google Groups "openthread-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openthread-use...@googlegroups.com.
To post to this group, send email to openthre...@googlegroups.com.

Jeremy Ellis

unread,
Apr 4, 2019, 3:22:16 AM4/4/19
to openthread-users
Of course. Nothing is ever easy. Thanks Jonathan. :)
To unsubscribe from this group and stop receiving emails from it, send an email to openthre...@googlegroups.com.

Jeremy Ellis

unread,
Oct 8, 2019, 11:12:07 AM10/8/19
to openthread-users
Jonathan you mentioned a while back: 

"For Particle and OTBR to communicate, they need to be configured with the same Thread Network configuration. There are two options:
  1. Configure OTBR to use the Particle device's Thread Network configuration.
  2. Configure Particle device to use OTBR's Thread Network configuration.
"

I have been working on option 1 for a while, but recently looked into option 2, which (Thanks to Jeff's suggestion) does seem to work. I have multiple Particle FTD devices (Argons) communicating with each other. My nrf52840 usb dongle using OTBR can scan and see the Particle devices.



For this to have any educational value, I need to be able to communicate between Openthread and Particle. Particle isolates a lot of the udp programming within their Mesh.publish() command.

I will dig into the code, but does anyone have any suggestions to help with OTBR communicating with the Particle devices?




Jeremy Ellis

unread,
Oct 23, 2019, 11:14:06 AM10/23/19
to openthread-users


So I have got Particle Mesh devices on openthread

blog at


video at



github at



but it still needs a serial connection with the OTBR. That is what I am working on next. I have some ideas but would really appreciate suggestions.

Here is my working code that needs www.po-util.com to compile





/*
* Particle Mesh Devices Connection with Openthread
* By Jeremy Ellis
* Twitter @rocksetta
* MIT license

* D0 to 3V3 send Mesh.publish to all devices flash D7
* D3 to 3V3 send Particle.publish to the console with generic information
* D6 to 3V3 disconnect wifi. Presently only works after wifi connected at startup.

* Warning, will need Argon binaries to get Particle back to normal
* v1.4.1-rc.1 found at the below link
* https://github.com/particle-iot/device-os/releases/download/v1.4.1-rc.1/particle_...@1.4.1-rc.1.zip
* Latest OS Device information found at the bottom of this blog
* https://community.particle.io/t/particle-device-os-updates-thread/14378/97
* files are in the \1.4.1-rc.1\argon\release\

* particle flash --usb argon-sys...@1.4.1-rc.1.bin
* reminder if you have to rer-install the boatloader you must flash in serial mode first then dfu for the system file
* particle flash --serial argon-bo...@1.4.1-rc.1.bin

* To run the below code you must install po-util with the following
* Might want to pre install git, node, npm and particle-cli
* sudo apt install curl
* bash <(curl -sL get.po-util.com)
* To check po-util version type
* po

* To start a po-util project
* po init argon myArgonProject
* cd myArgonProject

* po config mesh-develop 
* po setup-mesh

* MODULAR=n po argon build

* particle login
* particle list
* particle flash --usb myArgonProject-argon.bin

* Good idea between builds to clean
* po argon clean

*/

#include "Particle.h"

// uncomment the next line to improve stability
SYSTEM_THREAD(ENABLED);  // causes a small delay for Mesh.publish()

SYSTEM_MODE(SEMI_AUTOMATIC);  // so wifi not needed

//Next line allows you to use the Particle Featherwing plug and play
//STARTUP(System.enableFeature(FEATURE_ETHERNET_DETECTION)); 

#define OT_MASTER_KEY_SIZE 16

#include <assert.h>
#include "ot_api.h"
#include "openthread/dataset.h"

// Following line might be needed
//#include <openthread/thread_ftd.h>

#include <string.h>


extern "C" {

   int8_t               otLinkGetChannel(otInstance *aInstance);
   uint16_t             otLinkGetPanId(otInstance *aInstance);         
   otMasterKey         *otThreadGetMasterKey(otInstance *aInstance);
   char                *otThreadGetNetworkName(otInstance *aInstance);
   otOperationalDataset aDataset;

   void myHandler(const char *event, const char *data); 

};


/////////////////////////// important globals here ///////////////////////////////

int  myCode                     = 5;  // number of flashes
bool myXenonAntennaAttached     = false;  
bool myArgonBothAntennaAttached = false;  
bool myPublishToConsole         = true;        // set true for Argon for debugging

int myCount = 0;
bool myButtonReady = true;




/////////////////////////////// end globals ////////////////////////////


void setup() {   // runs once

   pinMode(D0, INPUT_PULLDOWN);   // set pin D0 as LOW input send Mesh.publish on HIGH
   pinMode(D3, INPUT_PULLDOWN);   // set pin D3 as LOW input send particle.publish on HIGH
   pinMode(D6, INPUT_PULLDOWN);   // set pin D6 as LOW input wifi off on HIGH
   pinMode(D7, OUTPUT);           // our trusty D7 LED
    
   if (digitalRead(D6) == 0){   // If D6 HIGH connect wifi
        Particle.connect();
   }

   Mesh.subscribe("mySendToAll", myHandler);
	
   if (myXenonAntennaAttached){
       #if (PLATFORM_ID == PLATFORM_XENON) 
	   digitalWrite(ANTSW1, 0);
	   digitalWrite(ANTSW2, 1);
       #endif  
   }
	
   if (myArgonBothAntennaAttached){
       #if (PLATFORM_ID == PLATFORM_ARGON) 
	   digitalWrite(ANTSW1, 1);
	   digitalWrite(ANTSW2, 0);
       #endif  
   }

   // Set Mesh Dataset	  
   memset(&aDataset, 0, sizeof(otOperationalDataset));

   /* Set Network Name to OTCodelab */
   static char aNetworkName[] = "OTCodelab";
   size_t length = strlen(aNetworkName);
   assert(length <= OT_NETWORK_NAME_MAX_SIZE);
   memcpy(aDataset.mNetworkName.m8, aNetworkName, length);
   aDataset.mComponents.mIsNetworkNamePresent = true;

   /*
     * Fields that can be configured in otOperationDataset to override defaults:
     *     Network Name, Mesh Local Prefix, Extended PAN ID, PAN ID, Delay Timer,
     *     Channel, Channel Mask Page 0, Network Master Key, PSKc, Security Policy
   */
   aDataset.mActiveTimestamp                      = 1;
   aDataset.mComponents.mIsActiveTimestampPresent = true;

   /* Set Channel to 15 */
   aDataset.mChannel                      = 15;
   aDataset.mComponents.mIsChannelPresent = true;

   /* Set Pan ID to 2222 */
   aDataset.mPanId                      = (otPanId)0x2222;
   aDataset.mComponents.mIsPanIdPresent = true;

   /* Set Extended Pan ID to C0DE1AB5C0DE1AB5 */
   uint8_t extPanId[OT_EXT_PAN_ID_SIZE] = {0xC0, 0xDE, 0x1A, 0xB5, 0xC0, 0xDE, 0x1A, 0xB5};
   memcpy(aDataset.mExtendedPanId.m8, extPanId, sizeof(aDataset.mExtendedPanId));
   aDataset.mComponents.mIsExtendedPanIdPresent = true;

   /* Set master key to 1234C0DE1AB51234C0DE1AB51234C0DE */
   uint8_t key[OT_MASTER_KEY_SIZE] = {0x12, 0x34, 0xC0, 0xDE, 0x1A, 0xB5, 0x12, 0x34, 0xC0, 0xDE, 0x1A, 0xB5};
   memcpy(aDataset.mMasterKey.m8, key, sizeof(aDataset.mMasterKey));
   aDataset.mComponents.mIsMasterKeyPresent = true;



}


void loop() {   // runs continuously

   myCount +=1;
    


   if (myButtonReady && digitalRead(D0) == 1){
      myCount = 0;
      digitalWrite(D7, 1);
      myButtonReady = false;
      
      Particle.publish("Sending Mesh Multicast", "...", 60, PRIVATE); 
      Mesh.publish("mySendToAll", String(myCode));  
      delay(1000);
      digitalWrite(D7, 0);
   }
   


   if (myButtonReady && digitalRead(D3) == 1){  // If D3 is HIGH print info to console


   // Must have an otInstance
      otInstance*  ot =    ot_get_instance();
      otDatasetSetActive(ot, &aDataset);

      char *myNetworkName = otThreadGetNetworkName(ot);
      char myNetworkNameBuff[255];
      snprintf(myNetworkNameBuff, sizeof(myNetworkNameBuff), "%s", myNetworkName); // network name as a string
	
      Particle.publish("Successful","Startup", 60, PRIVATE);	
      delay(2000);
      Particle.publish("My Network Name: ", String(myNetworkNameBuff), 60, PRIVATE); 
      delay(2000);
	
      // Mesh.localIP().toString().c_str());
      Particle.publish("My local ip: ", String(Mesh.localIP()), 60, PRIVATE); //shows local Mesh IPv4 address
      delay(2000);
   } 
 


   if (digitalRead(D6) == 0){  // If D6 is HIGH
      Particle.connect();      // I am a Photon (has Wifi)
   } else {
      Particle.disconnect();  // I am an Arduino (no Wifi)
   }


   if (myCount >= 1000){
      if (! myButtonReady){
        // Particle.publish("Next D7 can happen in ", "about 10 seconds", 60, PRIVATE); 
      }
      myButtonReady = true; 

   }
   delay(10);  // becomes about 5 seconds with the 1000 count 

}


// Event listener for "mySendToAll" event from Mesh Devices
void myHandler(const char *event, const char *data) {

   String parse = data;  //Cast char*data to String class
   int myNumber = parse.toInt();
   if (myPublishToConsole){  // mainly for Argon gateway unless debugging
      Particle.publish("Flashing D7 this many times:", parse, 60, PRIVATE); 
   }
   for (int myLoop = 0; myLoop < myNumber; myLoop++){
      digitalWrite(D7, HIGH);
      delay(200);   // very quick flash
      digitalWrite(D7, LOW);
      delay(200);   
   }
   delay(500); // to tell if 2 devices signal at similar times
}


Jeremy Ellis

unread,
Oct 24, 2019, 1:05:52 AM10/24/19
to openthre...@googlegroups.com


http://po-util.com used in my last post only works on linux and mac, so I just made a gitpod docker cloud browser version of it.





By the way I also made a gitpod of openthread



that github is at 



Reply all
Reply to author
Forward
0 new messages