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.

Modify AP as Data Hub example by sending message from AP to ED

Other Parts Discussed in Thread: SIMPLICITI

HI,

I'm using CC1110 to try this example. The example is the message send from ED to AP when button is pressed.

Now I change the code by sending message from AP to ED.

It doesn't work.

AP code as below:

void main (void)
{
  uint8_t     i;
  bspIState_t intState;
  uint8_t     msg[2];
 
  uint8_t     button, misses, done;
 
  BSP_Init();

  SMPL_Init(sCB);


  if (!BSP_LED2_IS_ON())
  {
    toggleLED(2);
  }
  if (!BSP_LED1_IS_ON())
  {
    toggleLED(1);
  }
  while (1)
  {
    uint8_t      noAck;
    smplStatus_t rc;
    button = 0;
    if (sJoinSem && (sNumCurrentPeers < NUM_CONNECTIONS))
    {
            while (1)
      {
        if (SMPL_SUCCESS == SMPL_LinkListen(&sLID[sNumCurrentPeers]))
        {
          break;
        }
              }

      sNumCurrentPeers++;
     
      BSP_ENTER_CRITICAL_SECTION(intState);
      sJoinSem--;
      BSP_EXIT_CRITICAL_SECTION(intState);

    }
    if (BSP_BUTTON1())
    {   /* Message to toggle LED 1. */
      button = 1;
    }
   
    if (button)
    {
 

      msg[0] = button;
      done = 0;
      while (!done)
      {
          for (i=0; i<sNumCurrentPeers; ++i)
          {
            noAck = 0;

            /* Try sending message MISSES_IN_A_ROW times looking for ack */
            for (misses=0; misses < MISSES_IN_A_ROW; ++misses)
            {
              if (SMPL_SUCCESS == (rc=SMPL_SendOpt(sLID[i], msg, sizeof(msg), SMPL_TXOPTION_ACKREQ)))
              {
                            toggleLED(1);
                break;
              }
              if (SMPL_NO_ACK == rc)
              {
                               noAck++;
              }
            }
            if (MISSES_IN_A_ROW == noAck)
            {
                           toggleLED(2);

            }
            else
            {
                          done = 1;
            }
          } 
      }   
    }
  }
}

void toggleLED(uint8_t which)
{
  if (1 == which)
  {
    BSP_TOGGLE_LED1();
  }
  else if (2 == which)
  {
    BSP_TOGGLE_LED2();
  }

  return;
}

static uint8_t sCB(linkID_t lid)
{
  if (~lid)
  {
    sJoinSem++;
   
  }
  return 0;
}

  • ED code:


    void main (void)
    {
      BSP_Init();

     
      while (SMPL_SUCCESS != SMPL_Init(0))
      {
        toggleLED(1);
        toggleLED(2);
        SPIN_ABOUT_A_SECOND;
      }


      if (!BSP_LED2_IS_ON())
      {
        toggleLED(2);
      }
      if (!BSP_LED1_IS_ON())
      {
        toggleLED(1);
      }


      linkTo();

      while (1) ;
    }

    static void linkTo()
    {
       uint8_t     msg[MAX_APP_PAYLOAD], len;

      while (SMPL_SUCCESS != SMPL_Link(&sLinkID1))
      {
        toggleLED(1);
        toggleLED(2);
        SPIN_ABOUT_A_SECOND;
       
      }


      if (BSP_LED2_IS_ON())
      {
        toggleLED(2);
      }
      if (BSP_LED1_IS_ON())
      {
        toggleLED(1);
      }
      while(1)
      {

        if (SMPL_SUCCESS == SMPL_Receive(sLinkID1, msg, &len))
        {
          processMessage(sLinkID1, msg, len);
          break;
        }
      }
     
    }  

     

    void toggleLED(uint8_t which)
    {
      if (1 == which)
      {
        BSP_TOGGLE_LED1();
      }
      else if (2 == which)
      {
        BSP_TOGGLE_LED2();
      }
      return;
    }

     

     

    static void processMessage(linkID_t lid, uint8_t *msg, uint8_t len)
    {

      if (len)
      {
        toggleLED(*msg);
      }
      return;
    }

     

    Please help

     

    Thanks

  • When you say "it doesn't work" what does that mean?  It doesn't work at all or the ED links to the AP, but then pressing the button on AP doesn't send the message to the ED. Where does it fail?

  • It can link but when it reach SendOpt, the sending is unsuccessful. from the code, did u see any mistake?

     

    Thanks

  • You currently have your SMPL_Receive call in a very type loop.  I would suggest implementing receive logic like it like it is done in the AP.  Define a call back function, sCB, that is called when data is received and then increment sPeerFrameSem in the call back function to indicate that data has been received. In the main loop call SMPL_Receive when sPeerFrameSem is greater than 0.

    Barry

  •  

    void main (void)

    {

      BSP_Init();

      while (SMPL_SUCCESS != SMPL_Init(sCB))

      {

        toggleLED(1);

        toggleLED(2);

        SPIN_ABOUT_A_SECOND;

      }

      if (!BSP_LED2_IS_ON())

      {

        toggleLED(2);

      }

      if (!BSP_LED1_IS_ON())

      {

        toggleLED(1);

      }

       uint8_t     msg[MAX_APP_PAYLOAD], len;

      while (SMPL_SUCCESS != SMPL_Link(&sLinkID1))

      {

        toggleLED(1);

        toggleLED(2);

        SPIN_ABOUT_A_SECOND;   

      }

      if (BSP_LED2_IS_ON())

      {

        toggleLED(2);

      }

      if (BSP_LED1_IS_ON())

      {

        toggleLED(1);

      }

     

      if(sPeerFrameSem)

      {

        if (SMPL_SUCCESS == SMPL_Receive(sLinkID1, msg, &len))

        {

          processMessage(sLinkID1, msg, len);

        }

        BSP_ENTER_CRITICAL_SECTION(intState);

        sPeerFrameSem--;

        BSP_EXIT_CRITICAL_SECTION(intState);

     

      }

     

    }   

     

     

     

    void toggleLED(uint8_t which)

    {

      if (1 == which)

      {

        BSP_TOGGLE_LED1();

      }

      else if (2 == which)

      {

        BSP_TOGGLE_LED2();

      }

      return;

    }

     

    static uint8_t sCB(linkID_t lid)

    {

      if (lid)

      {

        sPeerFrameSem++;  

      }

      return 0;

    }

     

     

    static void processMessage(linkID_t lid, uint8_t *msg, uint8_t len)

    {

      if (len)

      {

        toggleLED(*msg);

      }

      return;

    }

     

  • Hi,

     

    I had inserted the sCB into ED code. the sending still not successful. Is there any configuration we need to set?

    Any suggestion instead of the way I did?

     

    Thanks

    Ong 

  • Hi,

    You should wrap the checking of sPeerFrameSem in a while loop.  The way you have it written after it successfully links to the AP it will check once for incoming data and then it will exit.

    while (1)

    {

      if(sPeerFrameSem)

      {

        if (SMPL_SUCCESS == SMPL_Receive(sLinkID1, msg, &len))

        {

          processMessage(sLinkID1, msg, len);

        }

        BSP_ENTER_CRITICAL_SECTION(intState);

        sPeerFrameSem--;

        BSP_EXIT_CRITICAL_SECTION(intState);

       }

    }

    HTH,

    Barry

  • Hi

     

    Thanks for your help. One more question, any configuration we need to change in order to make AP receive message from ED? smpl_config.dat?

     

    Thanks

    Ong 

     

  • Hi,

    There shouldn't be.  Just ensure that the address (-DTHIS_DEVICE_ADDRSS) for the AP and ED are different.

    Barry

  • Hi,

     

     How about -DRX_POLLS ? I need to uncomment it? Any different if I uncomment it?

     

    Thanks

    Ong

  • No you shouldn't uncomment that. In your program you are not using polling you are using interrupts. That is how the sCB callback function is getting called.

    Cheers,

    Barry

  • Hi,

     

    Ok. Thanks a lots. I will try it again.

     

    Thanks

    Ong

  • Hi,

     

    I try many times, when I uncomment the -DRX_POLLS, the ED can receive message from AP. If I comment it, the ED cant receive any message.

    Is there any thing I missed out? any other configuration?

     

    Thanks

    Ong

  • Hi,

    Perhaps post your code again for the ED and AP and the steps you take to get the AP to send a message to the ED.  I would think that if your ED has linked to the AP, the AP should be able to send a message ED and you shouldn't have to have polling enabled.

    Barry

  • Hello.

    EDs by default do not have the radio in receive mode. It draws a lot of power to be in receive mode and EDs are assumed to be battery powered devices where power conservation is important. In the AP-as-data-hub example the ED does not receive application messages so RX is off. If you want the ED in this scenario to receive frames you must explicitly turn RX on using an ioctl call. There are examples in other projects of the SimpliciTI installation.

    Hope this helps.

    lfriedman

     

  • Hi,

    my code still same as previous code.

    the device address must be different right?

    Thanks

  • Hi,

    Which means I need to add this line?

    SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0);

    How about AP? do I need to add any code?

    Thanks

    Ong

  • Hi,

    lfriedman is absolutely right. You need to turn on the receiver with an IOCTL call such as               

    SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0);

    Call this after your ED has linked with the AP but before you start checking sPeerFramSem.

     

    Barry

  • Hi,

    how about device address? AP and ED must be different?

    Thanks

    Ong

  • Hi,

    If I change the JoinToken and I want to link it again. It need to initialize again? SMPL_Init()?

    Thanks

    Ong

  • Hi, Did you figure out your problem?

    I'm doing a similar project and I can't send/receive data.

  • Hello IFriedman,

    Just wanted to thank you for your post from almost two years ago....After days that I was straggling, reading your post made the breakthrough!

    Thanks for your help!!!

  • You are welcome.

    BTW, the same information was available in the Change Log document describing changes in the 1.0.5 release.

    lfriedman

  • May I ask another question?

    I'm trying to send  data from the AP to one ED and immediately after to a second ED.

    The first ED always gets the data but the second usually does not get it.

    Any idea why this is happening?

    Thanks