Sending Email From a Tessel Using SendGrid


Posted on

Tessel

When Technical Machine announced their JavaScript powered microcontroller almost a year ago, I immediately backed it once it popped up on the Dragon Innovation crowdfunding platform. Since their successful funding on October 5th 2013, I’ve been waiting.

Waiting for TODAY. When my Tessel microcontroller and GPRS Sim900 add-on module arrived after a two week trip from the US, to my house near Wimbledon, in London, via somewhere in Germany.

As I’m about to go on holiday, I don’t have a lot of time to dig in and really explore the uses but there was one thing I knew I could do pretty quickly – get it set up and send an email from it.

Set up the Tessel

After unpacking the unit from the anti-static bag, plug it in and run the following commands from terminal:

Write some code

In the above example I’ve used Needle for the HTTP request, so it needs to be added by creating a package.json file and declaring it in the dependencies. You could of course use the standard library HTTP request contained within NodeJS itself, but I think it looks ugly and over the top for an example like this, so I’ve used something cleaner and more readable.

Next we need to test the code. Tessel’s CLI includes a quick and easy way to test out what you’re building:

$ tessel run basic-tessel-app.js

The output of which should look something like this:

TESSEL! Connected to TM-00-04-f0009a30-005a433a-5e7465c2.
INFO Bundling directory /Users/martyndavies/code/tessel (~405.34 KB)
INFO Deploying bundle (562.50 KB)...
INFO Running script...

No errors, so hit the button and wait for the…

{ message: 'success' }

If everything works, push all the code to the Tessel so it persists:

$ tessel push basic-tessel-app.js

Happy days! Now here are some caveats…

It’s early days for Tessel. That’s cool, they’ve achieved a lot and the board is great fun to hack with. There are also lots of updates and lots of work on compatibility, but here are some things I struggled with that are worth noting:

  • Why not use sendgrid-nodejs? I tried but one of the other libs that it depends on isn’t compatible with Tessel, so it fails when trying to load.
  • Why not use Request? See above.
  • Tessel WiFi can be problematic. A lot of time was wasted on being too far away from my router for requests to successfully complete but not really knowing why.

Relatively trivial and I’m sure this won’t be the case for too long. I look forward to digging into this board further now that the awesome Cylon.js is ready for it.


Martyn Davies is a Developer Evangelist at SendGrid and a creative developer based in London. He has worked in technology for over 14 years with a background in both the music industry and technology. A serial hackathon organiser, mentor and startup advisor, you’ll find him presenting, demoing, hacking and chatting at hack days, conferences and meetups in the UK & Europe on a regular basis.

Have thoughts on this post?
Chat with us about it on Twitter and Google+