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.

Smart RF06 board with cc2538: Contiki Web Sockets example

Other Parts Discussed in Thread: CC2650

I hope this is the right forum. I am trying to execute a simple web sockets demo as documented here: http://www.slideshare.net/ADunkels/building-day-1-upload-3

I have downloaded the latest device firmware from the Thingsquare site and registered my devices with http://demo.thsq.io

Some of the simple demos I have found work: Hello World, Blink the LEDs, etc. I am using the Develop UI on the Thingsquare site to do this rather than compiling and pushing a new firmware image to the device with the TI tool.

But the websockets example does not work. Here is the code for the device side (I have fuzzed the ip address but the one I use is real -- I can send web socket messages to it from a node.js client):

#include "thsq.h"

#include "websocket.h"

static struct websocket s;

PROCESS(websocket_example_process, "Websocket Example");
AUTOSTART_PROCESSES(&websocket_example_process);

/*---------------------------------------------------------------------------*/
static void
callback(struct websocket *s, websocket_result r,
         uint8_t *data, uint16_t datalen)
{
  if(r == WEBSOCKET_CONNECTED) {
     websocket_send_str(s, "Connected");
  } else if(r == WEBSOCKET_DATA) {
     char buf[100];
     snprintf(buf, sizeof(buf), "%.*s", datalen, data);
     thsq_client_set_str("data", buf);
  }
  thsq_client_push();
}

/*---------------------------------------------------------------------------*/
PROCESS_THREAD(websocket_example_process, ev, data)
{
  static struct etimer et;
  PROCESS_EXITHANDLER(websocket_close(&s));
  PROCESS_BEGIN();
  
  websocket_open(&s, "ws://xx.xx.xx.xx:8080/",
  	"thingsquare", callback);

  while(1) {
    etimer_set(&et, CLOCK_SECOND * 10);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
    websocket_send_str(&s, "hello");
  }

  PROCESS_END();
}

Can anyone see any issues with this code? The Server is a simple node.js server definition that works with other client connections.

If there is a better forum for these questions, I will gladly move there.

  • Well, my non-working experience was in the office where I have a suspicion that certain kinds of traffic are blackholed or otherwise interfered with -- perhaps websocket traffic over 8080?. I had to connect my gateway there into a switch in our Lab to get connectivity to the Thingsquare demo site to begin with. The devices in general though could be anywhere in the office.

    When I came home, where I also have another experimental test bed including one device configured as a gateway and one as an ordinary device, I tried the same experiment. I am running ordinary consumer internet through a well-known provider.

    And I was surprised to see the code above working as intended. I was seeing traffic to and from the node.js server.

    So it's good to see that the code itself is fine as written. Now I have to figure out how to make things work in the office proper. I may need to see if ports are blocked or what.

    Jim

  • Thanks, glad you were able to get it resolved

  • Hi Jim, 

    I had a similar problem when trying the devices in our Lab, after having ensure the code by trying it at home, the only possibility is that either the network used in the university does not allow connections that are not verified (i.e. MAC address needs to be in the data base of the university, as was my case ) or simply a firewall is preventing it's traffic.

    Try this second possibility first as it's faster, and if that does not  contact the office of technology services from your lab. It would depend on what kind of security your network relies on.

    And if you had already solve this, please ignore my comments and post your solution here for future users with the same issue. 

    Good luck, 

    Jorge

  • Hi Jorge,

    I am trying to create a websocket project similar to Thingsquare example, but using a different hardware platforms, specifically CC2650 sensortag.

    and using nodejs on local PC.

    I was able to find the source code for the motes (websocket-example), but not for the edge router.

    Is it available? If yes, can you kindly pass a link?

    Jan