Puck.js With Sms Control

About the project

This video shows you how use Puck.js and a GSM modem to control devices via SMS text messages.

Project info

Difficulty: Easy

Platforms: Espruino

Estimated time: 2 hours

License: Apache License 2.0 (Apache-2.0)

Items used in this project

Hardware components

patch wires patch wires x 1
breadboard breadboard http://www.espruino.com/Breadboard x 1
5v power source 5v power source x 1
3.3v voltage regulator 3.3v voltage regulator x 1
SIMCom SIM800/SIM900 GSM/GPRS Module SIMCom SIM800/SIM900 GSM/GPRS Module x 1
Puck.js device Puck.js device http://www.espruino.com/Puck.js x 1
Espruino Puck.js v2 Espruino Puck.js v2 x 1

Story

This video shows you how use Puck.js and a GSM modem to control devices via SMS text messages.


The video further down shows how to read data from BLE devices within range and then send that as an SMS text message response.

Note: You'll need the latest firmware as of Sept 2017 on your Puck.js device for this. That means at least 1v95 (when released) or a 'cutting edge' build (http://www.espruino.com/Download).

Wiring Up

Connect as follows:


Software

Controlling Puck.js's LED from an SMS


  1. Bluetooth.setConsole(1);
  2. Serial1.setup(115200, { rx: D29, tx : D28 });
  3. var ATSMS = require("ATSMS");
  4. var sms = new ATSMS(Serial1);
  5.  
  6. sms.init(function(err) {
  7. if (err) throw err;
  8. console.log("Initialised!");
  9.  
  10. sms.list("ALL", function(err,list) {
  11. if (err) throw err;
  12. if (list.length)
  13. console.log(list);
  14. else
  15. console.log("No Messages");
  16. });
  17.  
  18. // and to send a message:
  19. //sms.send('+441234567890','Hello world!', callback)
  20. });
  21.  
  22. sms.on('message', function(msg) {
  23. console.log("Got message #",msg);
  24. sms.get(msg, function(err, msg) {
  25. if (err) throw err;
  26. print("Read message", msg);
  27. var txt = msg.text.toLowerCase();
  28. if (txt=="on") LED1.set();
  29. if (txt=="off") LED1.reset();
  30. // delete all messages to stop us overflowing
  31. sms.delete("ALL");
  32. });
  33. });

Controlling an Awox BLE Lightbulb

  1. Bluetooth.setConsole(1);
  2. Serial1.setup(115200, { rx: D29, tx : D28 });
  3. var ATSMS = require("ATSMS");
  4. var sms = new ATSMS(Serial1);
  5.  
  6. sms.init(function(err) {
  7. if (err) throw err;
  8. console.log("Initialised!");
  9.  
  10. sms.list("ALL", function(err,list) {
  11. if (err) throw err;
  12. if (list.length)
  13. console.log(list);
  14. else
  15. console.log("No Messages");
  16. });
  17.  
  18. // and to send a message:
  19. //sms.send('+441234567890','Hello world!', callback)
  20. });
  21.  
  22. sms.on('message', function(msg) {
  23. console.log("Got message #",msg);
  24. sms.get(msg, function(err, msg) {
  25. if (err) throw err;
  26. print("Read message");
  27. var txt = msg.text.toLowerCase();
  28. if (txt=="on") setLight(1);
  29. if (txt=="off") setLight(0);
  30. // delete all messages to stop us overflowing
  31. sms.delete("ALL");
  32. });
  33. });
  34.  
  35. function setLight(isOn) {
  36. var gatt;
  37. NRF.connect("98:7b:f3:61:1c:22").then(function(g) {
  38. // ^^^^^^^^^^^^^^^^^ your light's address here
  39. gatt = g;
  40. return gatt.getPrimaryService("33160fb9-5b27-4e70-b0f8-ff411e3ae078");
  41. }).then(function(service) {
  42. return service.getCharacteristic("217887f8-0af2-4002-9c05-24c9ecf71600");
  43. }).then(function(characteristic) {
  44. return characteristic.writeValue(isOn ? 1 : 0);
  45. }).then(function() {
  46. gatt.disconnect();
  47. console.log("Done!");
  48. });
  49. }

Returning temperature


The code on the Puck.js sending the temperature is:


  1. setInterval(function() {
  2. NRF.setAdvertising({
  3. 0x1809 : [Math.round(E.getTemperature())]
  4. });
  5. }, 30000);

and the full source is:


  1. Bluetooth.setConsole(1);
  2. Serial1.setup(115200, { rx: D29, tx : D28 });
  3. var ATSMS = require("ATSMS");
  4. var sms = new ATSMS(Serial1);
  5.  
  6. sms.init(function(err) {
  7. if (err) throw err;
  8. console.log("Initialised!");
  9.  
  10. sms.list("ALL", function(err,list) {
  11. if (err) throw err;
  12. if (list.length)
  13. console.log(list);
  14. else
  15. console.log("No Messages");
  16. });
  17.  
  18. // and to send a message:
  19. //sms.send('+441234567890','Hello world!', callback)
  20. });
  21.  
  22. sms.on('message', function(msg) {
  23. console.log("Got message #",msg);
  24. sms.get(msg, function(err, msg) {
  25. if (err) throw err;
  26. print("Read message", msg);
  27. var txt = msg.text.toLowerCase();
  28. if (txt=="on") LED1.set();
  29. if (txt=="off") LED1.reset();
  30. if (txt=="get") getTemp(msg.oaddr);
  31. // delete all messages to stop us overflowing
  32. sms.delete("ALL");
  33. });
  34. });
  35.  
  36. function getTemp(number) {
  37. console.log("Getting temp");
  38. NRF.findDevices(function(devs) {
  39. devs.forEach(function(dev) {
  40. if (dev.name=="Puck.js 5736") { // <--- change this to the name of your Puck.js
  41. console.log("Got temp");
  42. var message = "Temp is "+dev.serviceData["1809"][0];
  43. sms.send(number,message, function() {
  44. print("Sent text!");
  45. });
  46. }
  47. });
  48. });
  49. }

Buying

See the Puck.js Lightbulb page for links to where to find the Awox lights for sale.

The SIM900 page has links to where to find the SIM900 module.

Puck.js devices can be ordered from here

Credits

Photo of Espruino

Espruino

Espruino, Espruino Pico and Puck.js are low-power Microcontrollers that run JavaScript. Espruino is a JavaScript Interpreter for Microcontrollers that is designed to make development quick and easy. The Espruino interpreter is firmware that runs on a variety of different microcontrollers, but we also make Espruino Boards that come with the interpreter pre-installed and are the easiest devices to get started with. However Espruino itself isn't just the interpreter firmware or hardware - there's also the Web IDE, command-line tools, documentation, tutorials, and modules that form a complete solution for embedded software development.

   

Leave your feedback...