Most recent activity
-
-
For those with Espruino Pico, this opens TLS connection from espruino to socat, and TLS v1.2 from socat to AWS IoT.
root@192.168.2.1> socat openssl-listen:8883,fork,reuseaddr,cert="$HOME/Downloads/61a57a0f66-certificate.pem.crt",key="$HOME/Downloads/61a57a0f66-private.pem.key",verify=0 openssl-connect:A4B6O0T19QBXJ.iot.ap-northeast-1.amazonaws.com:8883,method=TLS1.2,cert="$HOME/Downloads/61a57a0f66-certificate.pem.crt",key="$HOME/Downloads/61a57a0f66-private.pem.key",cafile="$HOME/Downloads/VeriSign-Class 3-Public-Primary-Certification-Authority-G5.pem",verify=1
function initEthernet(cb) { SPI2.setup({ mosi:B15, miso:B14, sck:B13 }); var eth = require("WIZnet").connect(SPI2, B10); eth.setIP(); global.eth = eth; if('function' === typeof cb){cb();} } function initMQTT(cb) { var mqtt = require("MQTT").create(); mqtt.on('connected', function() { mqtt.subscribe("$aws/things/+/shadow/#"); mqtt.on('publish', function (pub) { console.log("topic: "+pub.topic); console.log("message: "+pub.message); }); if('function' === typeof cb){cb();} }); require("tls").connect("mqtts://192.168.2.1:8883", function(conn) { mqtt.connect(conn); global.mqtt = mqtt; }); } //E.on('init', initEthernet); //E.on('init', initMQTT); //save(); initEthernet(function() { console.log(global.eth.getIP()); initMQTT(function() { console.log("AWS IoT Ready"); }); });
-
Partially ported AWS IoT library.
As there is currently no support for client-cert X.509 auth yet on Espruino, use with socat.Created pull requests on github:
github.com/espruino/EspruinoDocsĀ/pull/193
github.com/espruino/EspruinoDocsĀ/pull/194Managed to connect to AWS IoT by offloading tls to socat.
root@192.168.2.1> socat tcp-listen:8883,fork,reuseaddr openssl-connect:A4B6O0T19QBXJ.iot.ap-northeast-1.amazonaws.com:8883,method=TLS1.2,cert="$HOME/Downloads/61a57a0f66-certificate.pem.crt",key="$HOME/Downloads/61a57a0f66-private.pem.key",cafile="$HOME/Downloads/VeriSign-Class 3-Public-Primary-Certification-Authority-G5.pem"
function initEthernet(cb) { SPI2.setup({ mosi:B15, miso:B14, sck:B13 }); var eth = require("WIZnet").connect(SPI2, B10); eth.setIP(); global.eth = eth; if('function' === typeof cb){cb();} } function initMQTT(cb) { var mqtt = require("MQTT").create("192.168.2.1", { port: 8883 }); mqtt.on('connected', function() { mqtt.subscribe("$aws/things/+/shadow/#"); mqtt.on('publish', function (pub) { console.log("topic: "+pub.topic); console.log("message: "+pub.message); }); if('function' === typeof cb){cb();} }); mqtt.connect(); global.mqtt = mqtt; } function initAwsIotDevice(cb) { var awsIot = {}; awsIot.device = require('aws-iot-device-sdk-device'); var device = awsIot.device({ host: '192.168.2.1', port: 8883 }); device.on('connect', function() { console.log('connect'); device.subscribe('$aws/things/+/shadow/#'); device.publish('$aws/things/espruino1/shadow/test', JSON.stringify({test_data:1})); if('function' === typeof cb){cb();} }); device.on('message', function(topic, payload) { console.log('message', topic, payload.toString()); }); } function initAwsIotThingShadow(cb) { var awsIot = {}; awsIot.thingShadow = require('aws-iot-device-sdk-thing'); var thingShadows = awsIot.thingShadow({ host: '192.168.2.1', port: 8883 }); var rgbLedLampState = {"state":{"desired":{"red":187,"green":114,"blue":222}}}; thingShadows.on('connect', function() { thingShadows.register('espruino1'); }); } //E.on('init', initEthernet); //E.on('init', initMQTT); //save(); initEthernet(function() { console.log(global.eth.getIP()); initMQTT(function() { console.log("AWS IoT Ready"); }); });
root@192.168.2.1> mosquitto_pub -h 192.168.2.1 -p 8883 -d -t '$aws/things/espruino1/shadow/test' -m "Hello World"
AWS IoT device library is working.
Will continue to port AWS IoT shadow things library from nodejs. -
I would like to be able to reconnect via serial after tcp connection has closed, it there a way to do it?
// Telnet Server require("net").createServer(function (connection) { connection.pipe(LoopbackA); LoopbackA.pipe(connection); LoopbackB.setConsole(); connection.on('close', function() { // TODO }); if(!global.fullreset) { global.fullreset = global.reset; global.reset = softreset; } }).listen(23);
-
Found a bug in Array.indexOf implementation.
Only strings less than 5 characters matches.global.keep = ["keep", "onInit", "SPI", "SPI2", "Ethernet", "eth", "Server", "Socket", "Serial", "Pipe", "LoopbackA", "LoopbackB", "fullreset", "reset"]; function softreset() { Object.keys(global).forEach(function(n) { console.log("-"+n+"-"); console.log(global.keep.indexOf(n)); });
Should I open a new topic?
-
-
For the wiznet, this is what I use:
function onInit() { // Ethernet Card SPI2.setup({ mosi:B15, miso:B14, sck:B13 }); var eth = require("WIZnet").connect(SPI2, B10); eth.setIP(); global.eth = eth; // Prevent reset function softreset() { clearInterval(); clearWatch(); Object.keys(global).forEach(function(n) { if(n!="onInit" && n!="Ethernet" && n!="Server" && n!="Socket" && n!="Serial" && n!="Pipe" && n!="LoopbackA" && n!="LoopbackB" && n!="eth" && n!="fullreset" && n!="reset") { delete global[n]; } }); console.log("Can't reset properly - we'd break the network. Use fullreset() instead."); } // Telnet Server require("net").createServer(function (connection) { connection.pipe(LoopbackA); LoopbackA.pipe(connection); LoopbackB.setConsole(); if(!global.fullreset) { global.fullreset = global.reset; global.reset = softreset; } }).listen(23); } //save();
(Updated with Gordon's tip)
I'm looking forward to the new Wifi and the BLE Espruino boards. Just sad that a lot of BLE light bulbs and BLE smart-things don't have an open and standardized BLE protocol, which makes communicating with them hard. Wonder whether there is a tracing tool for BLE to reverse engineer the packets sent by those proprietary android apps... like wireshark or car hacking over Canb.us. Maybe the BLE Espruino should be able to record and replay whatever it has heard over the air?