July 5, 2014

NodeJS Simple Web Server on the Tessel

As I mentioned in my last post, I recently received a Tessel in the mail. After running the blinky.js example, I moved on to a more traditional “Hello World” exercise with the simple server example from the NodeJS homepage.

I was getting mixed results with tessel run but, when I wrote my code to flash with tessel push, the Tessel became unresponsive. I tried different IP addresses and ports, but, each time I tried to write the revised code to flash, I would receive the “Error writing USB message endpoint” message. I would then have to put the Tessel into bootloader mode (i.e. Push the reset button. Push the config button. Release the config button.) and run tessel erase --force.

Putting the Tessel into bootloader mode

  • Push the reset button.
  • Push the config button.
  • Release the config button.

I posted this message to the forums. Shortly thereafter, Kevin Mehall from Technical Machine got me back on track with his response.

The long and the short of it is that http.createServer was executing before the CC3000 had connected to the Wifi network, resulting in the Tessel locking up. I wrapped the simple server example in a timeout and am now able to connect to the server which displays a “Hello World!” message and write code to flash as expected.

Here’s the code:

var http = require( 'http' );
setTimeout( function() {
	http.createServer( function (req, res) {
		res.writeHead( 200, {'Content-Type': 'text/plain'} );
		res.end('Hello World!\n');
	}).listen( 80 );
}, 10000 );

As always, I hope this saves someone out there a bit of time. Feel free to get in touch if you have any questions.