MBED+WEBSERVER+XBEE+RPC

12 May 2014

Hi all,

The code below activates LEDs and relays on two boards with xbee, how do I change the code to work on a web application running in a browser using RPC or other form of remote serial communication?

include the mbed library with this snippet

#include "mbed.h"

Serial xbee1(p13,p14);
DigitalOut rst1(p11); //Digital reset for the XBee, 200ns for reset
DigitalOut myled(LED3);//Create variable for Led 3 on the mbed

int main()
{
    rst1 = 0; //Set reset pin to 0
    myled = 0;//Set LED3 to 0
    wait_ms(1);//Wait at least one millisecond
    rst1 = 1;//Set reset pin to 1
    wait_ms(1);//Wait another millisecond
    
    while (1) {//Neverending Loop
        myled = 1; //Turn Led 3 Off
        //Frame XBEE 1 turn on relay 
        xbee1.putc(0x7E);         //start byte of API frame
        xbee1.putc(0x00);          //high part of length.It always zero
        xbee1.putc(0x10);         //low part of length.The number of bytes that follow,not including checksum
        xbee1.putc(0x17);         // frame type.In this case 0x17 is a remote AT command
        xbee1.putc(0x05);         //Frame ID.No acknowledgment is needed.The remote xbee will receive what we send
        xbee1.putc(0x00);
        xbee1.putc(0x13); //XBEE ANDRESS
        xbee1.putc(0xA2);  //XBEE ANDRESS
        xbee1.putc(0x00);//XBEE ANDRESS
        xbee1.putc(0x40);//XBEE ANDRESS
        xbee1.putc(0xA1);  ///XBEE ANDRESS
        xbee1.putc(0x3A);  //XBEE ANDRESS
        xbee1.putc(0xB6);  //XBEE ANDRESS
        xbee1.putc(0xFF);
        xbee1.putc(0xFE);
        xbee1.putc(0x02);
        xbee1.putc(0x44);    // command name in ASCII characters "D"
        xbee1.putc(0x34);    // command name in ASCII characters "4"
        xbee1.putc(0x05);    // D 4 HIGH
        xbee1.putc(0xE1);    //CHECKSUM
        wait(1);
        myled = 0; //Turn Led 3 on for succcessfull communication
        wait(1);
      
//Frame XBEE 1 turn off relay 
        xbee1.putc(0x7E);         //start byte of API frame
        xbee1.putc(0x00);          //high part of length.It always zero
        xbee1.putc(0x10);         //low part of length.The number of bytes that follow,not including checksum
        xbee1.putc(0x17);         // frame type.In this case 0x17 is a remote AT command
        xbee1.putc(0x05);         //Frame ID.No acknowledgment is needed.The remote xbee will receive what we send
        xbee1.putc(0x00);
        xbee1.putc(0x13); //XBEE ANDRESS
        xbee1.putc(0xA2); //XBEE ANDRESS
        xbee1.putc(0x00);//XBEE ANDRESS
        xbee1.putc(0x40);//XBEE ANDRESS
        xbee1.putc(0xA1); //XBEE ANDRESS
        xbee1.putc(0x3A); //XBEE ANDRESS
        xbee1.putc(0xB6);  //XBEE ANDRESS
        xbee1.putc(0xFF);
        xbee1.putc(0xFE);
        xbee1.putc(0x02);
        xbee1.putc(0x44);  // command name in ASCII characters "D"
        xbee1.putc(0x34);// command name in ASCII characters "4"
        xbee1.putc(0x04);// D 4 LOW
        xbee1.putc(0xE2);//CHECKSUM

        wait(1);

        //Frame XBEE 2 turn on relay 

        xbee1.putc(0x7E);         //start byte of API frame
        xbee1.putc(0x00);          //high part of length.It always zero
        xbee1.putc(0x10);         //low part of length.The number of bytes that follow,not including checksum
        xbee1.putc(0x17);         // frame type.In this case 0x17 is a remote AT command
        xbee1.putc(0x05);         //Frame ID.No acknowledgment is needed.The remote xbee will receive what we send
        xbee1.putc(0x00);
        xbee1.putc(0x13);
        xbee1.putc(0xA2);
        xbee1.putc(0x00);
        xbee1.putc(0x40);
        xbee1.putc(0xA0);
        xbee1.putc(0x40);
        xbee1.putc(0x37);
        xbee1.putc(0xFF);
        xbee1.putc(0xFE);
        xbee1.putc(0x02);
        xbee1.putc(0x44);
        xbee1.putc(0x34);
        xbee1.putc(0x05);
        xbee1.putc(0x5B);

        wait(1);

//Frame XBEE 2 turn off relay 
        xbee1.putc(0x7E);         //start byte of API frame
        xbee1.putc(0x00);          //high part of length.It always zero
        xbee1.putc(0x10);         //low part of length.The number of bytes that follow,not including checksum
        xbee1.putc(0x17);         // frame type.In this case 0x17 is a remote AT command
        xbee1.putc(0x05);         //Frame ID.No acknowledgment is needed.The remote xbee will receive what we send
        xbee1.putc(0x00);
        xbee1.putc(0x13);
        xbee1.putc(0xA2);
        xbee1.putc(0x00);
        xbee1.putc(0x40);
        xbee1.putc(0xA0);
        xbee1.putc(0x40);  
        xbee1.putc(0x37);   
        xbee1.putc(0xFF);   
        xbee1.putc(0xFE);          
        xbee1.putc(0x02);    
        xbee1.putc(0x44);    
        xbee1.putc(0x34);
        xbee1.putc(0x04);
        xbee1.putc(0x5C);
       
wait(1);     
        }
    }