-
-
Have a look at this code for some ideas on Post and Get
http://forum.espruino.com/conversations/292196/#comment13195299
-
-
Doing some more digging
In contrast, the Magellan Echo Smart Sports Watch was designed as an open platform and can work with any application that can leverage a ruggedized smartwatch in several colors (Figure 3, right). The watch leverages the power of both a smartphone and sports-related apps. It uses Bluetooth Smart to connect a smartphone and watch, putting the power of a smartphone right on the user’s wrist. An ARM® Cortex®-M3 runs the watch while a Bluetooth chip from Nordic Semiconductor provides the communications, and ST Micro supplies the accelerometer. Echo is compatible today with the iPhone 4S, 5, 5C and 5S. Android support is coming in early 2014.
http://chipdesignmag.com/sld/blog/tag/wifi/The 32-bit Giant Gecko MCU, based on the ARM® Cortex®-M3 core, also plays a key role in the sport watch’s energy efficiency, enabling the Echo to operate for up to 11 months on a single CR2032 coin-cell battery. The Magellan Echo design team achieved their ultra-low energy goals by optimizing the Giant Gecko MCU’s five different energy modes and leveraging the MCU’s low-energy sensor interface (LESENSE) and peripheral reflex system (PRS). These features enable energy-friendly and autonomous peripherals to handle timing and sensor control without involving the CPU.
http://www.businesswire.com/news/home/20140106005026/en/Silicon-Labs-Giant-Gecko-MCU-Enables-Echo
-
Lots of interest so I did a little surfing to find out more. These links seemed to point to Magellian Echo One link to Amazon shows a price of $22.00.
Also found another chip Taiyo Yuden Bluetooth® Smart Modules based on ARM Cortex M0 32bit processor, ARM Cortex M4F 32bit processor.Searching for Magellan’s Echo produced these links:
https://www.amazon.com/dp/B00FZHUNSC?encoding=UTF8&ref=de_a_smtd&showDetailTechData=1#technical-datahttps://devzone.nordicsemi.com/blogs/792/new-features-in-nrf52/
So does the Magellan Echo look like a worthy purchase?
-
Glad that you have found a solution.
I'm running a Windows 7 system with WebIDE.
I tried it at all levels of minification with no problem.
The only way I could get an error is if my phat fingers missed the shift key when typing the pins. b7 instead of B7. I usually run the Esprima (offline) minification.
I also tried the Serial stuff using the terminal program Putty with positive results.
Welcome to the Art of computer programming. It's art when variables won't and constants aren't :) -
Are you using WEBIDE to access the PICO?
Here's another example using the options://PICO v1.86 var baudrate=9600; var Port=Serial1; var P={rx:B7, tx:B6,bytesize:8,parity:'even',stopbits:1}; //var Port=Serial2; //var P={rx:A3, tx:A2,bytesize:8,parity:'even',stopbits:1}; Port.setup(baudrate,P); //loopback jumper the tx and rx pins together to test Port.on('data', function (data) { print("Serial> "+data); }); Port.print("Hello World");
The output:
>echo(0); =undefined Serial> H Serial> e Serial> l Serial> l Serial> l Serial> o Serial> Serial> W Serial> o Serial> r Serial> l Serial> d >
-
-
-
-
//strings.js var A="1234567890"; var B=A; console.log(B);console.log(B.length); B=B+B; console.log(B);console.log(B.length); //out of memory if continued //B=B+B; //console.log(B);console.log(B.length); //B=B+B; //console.log(B);console.log(B.length); B=A; console.log(B);console.log(B.length); B+=B; console.log(B);console.log(B.length); B+=B; console.log(B);console.log(B.length);
Produces:
>echo(0); 1234567890 10 12345678901234567890 20 1234567890 10 12345678901234567890 20 ERROR: Out of Memory! WARNING: Out of memory while appending to array Execution Interrupted =undefined >
-
A yellow triangle warning appears in WebIDE that flags the escapement.
//unnecessaryEscapment.js //PICO v 1x86 // A is flagged as unecessary escapment // with a yellow triangle in the right side of WEBIDE var A="\x31"; var B="x31"; console.log("A= ",A); console.log("B= ",B);
The output:
>echo(0); A= 1 B= x31 =undefined >
-
On the client side
"free": 1827, "usage": 3273, "total": 5100, "history": 3,
"stackEndAddress": 536959420, "flash_start": 134217728, "flash_binary_end": 376280, "flash_code_start": 134234112, "flash_length": 393216 }On the server side
console.log(process.memory());
{ "free": 2323, "usage": 2777, "total": 5100, "history": 2084,
"stackEndAddress": 536959420, "flash_start": 134217728, "flash_binary_end": 376280, "flash_code_start": 134234112, "flash_length": 393216 }
=undefinedThe code can shrink as there is a lot of stuff used to debug and illustrate its operation. Code that saves messages for replay can go. Don't need to display the keys and messages.
A couple of ideas:
Set it up like a crypto modem. Send commands via serial to one PICO over USB or serial port.
The PICO sends it securely to a second PICO which sends it out the USB or serial port.
There is a lexlevel associated with UserId and password so that one lex level controls the server PICO pins and another would send commands out the serial port.
On the to do list is to break out a user defined payload object. As currently written that would give you 31 bytes to define user commands. It could take several SCADA protocols without much effort. A rewrite for some of the longer ones. -
-
ServerKM3init.js and ClientKM3.js 4 Sep. 2016
These files incorporate the Kryptomessage protocol into two different PICOs each connected to an ESP8266 using the PICO shim.
The Squirt utility was used to write the cryptographic keys into the EPROM on each PICO. See previous posts for modules and squirt.js
To run these programs you will need to “Squirt” the keys into the PICOs.
Edit ServerKM3init.js with your router information:
var SSID="router SSID";
var key= "router key";
Load Server KM3init.js into the first PICO and enter “save();” into the left screen.
It should save the program so that at power up the program will run. It usually goes on to connect to the router. Note the server IP address. With a browser you can pull the server up by using http://192.168.1.4:8080/ where 192.168.1.4 is the IP address. Your server IP address may be different
With the second client PICO pull up ClientKM3.js and edit the following with your local information.
ServerIP="192.168.1.4";
//setup WiFi access parameters
var RouterSSID="router SSID";
var Routerkey= "routerkey";
Load and run ClientKM3.js.
At this point, I disconnect from the client PICO and reconnect with the Server PICO using WebIDE. I use Putty (or another terminal program, to connect to the Client PICO at 155,200 baud.The Client Screen using Putty
8 do LEDoff Client user message Permutated Encrypted Message= e6,f8,af,13,54,7e,b7,e9,3b,c0,7e,95,2b,6b,14,4c, 15,24,41,37,ae,36,76,18,d2,bc,31,ae,3d,62,74,9a, ed,e1,3d,f,7d,1,10,c6,ea,66,b,de,bc,27,72,6c, e1,cf,2a,b4,2f,1a,b7,e,4a,ef,a6,43,30,cf,9,d0, 57,3b,9a,c7,e9,3a,e6,10,2a,83,ef,9b,a5,6a,d8,db, 80 192.168.1.4 send Closed: 80 process client decrypt Client checks the server message Client check of server msg OK Client checks if the server is authentic Server is Authentic Client sees msg 0x43 Select using digit and return key 1 Connect 6 Cshow 2 Logoff 7 LEDon 3 Creplay 8 LEDoff 4 Creset 9 Read ADC 5 n/a 0 Exit { "free": 2311, "usage": 2789, "total": 5100, "history": 2021, "stackEndAddress": 536959420, "flash_start": 134217728, "flash_binary_end": 376280, "flash_code_start": 134234112, "flash_length": 393216 } >
The Server Screen:
decrypt Server checks the client message Server check of client msg OK Server checks if the client authentic Server check of client authenticity OK Permutated Encrypted Message= 5a,7f,c2,cd,3d,c3,1d,c6,c3,a3,b6,f9,6e,cd,2f,b1, 52,b0,27,b5,ae,8b,5c,29,48,9f,70,a,3d,51,7,3a, 4f,a1,f2,17,7,d1,cf,f5,d5,b6,76,ad,b4,46,d3,db, 7f,d0,b2,c7,8a,48,e7,4f,f9,1d,b2,41,46,b8,23,44, 8e,29,13,33,fd,5b,9b,21,9d,73,3,30,d9,54,e4,e8, server transmits Close= false Post Post length= 80 doing command process server undefined e6,f8,af,13,54,7e,b7,e9,3b,c0,7e,95,2b,6b,14,4c, 15,24,41,37,ae,36,76,18,d2,bc,31,ae,3d,62,74,9a, ed,e1,3d,f,7d,1,10,c6,ea,66,b,de,bc,27,72,6c, e1,cf,2a,b4,2f,1a,b7,e,4a,ef,a6,43,30,cf,9,d0, 57,3b,9a,c7,e9,3a,e6,10,2a,83,ef,9b,a5,6a,d8,db, decrypt Server checks the client message Server check of client msg OK Server checks if the client authentic Server check of client authenticity OK Permutated Encrypted Message= fb,c3,53,2,49,68,36,87,4a,28,cd,f8,55,b9,bf,79, 16,2d,6b,39,af,ec,d5,ee,b2,2c,d7,77,12,83,88,ed, 50,9c,29,30,2a,c3,3e,2,a7,3,18,f9,7a,48,ef,2a, 5,57,f7,cd,71,c7,17,f1,52,16,4e,17,e6,da,5e,c0, c8,a5,3b,1f,22,a0,6e,5f,6d,fc,78,25,3a,96,12,57, server transmits Close= false
User ID = "Sam" Password "1234"
-
Hi @MaBe">@MaBe .
I'm not working on HTTPS.
I am currently polishing a working version of the Cryptographic Protocol (CP) that uses HTTP Post and reply as a communications link.The CP is designed for use with the low cryptographic entropy of control messages. How to protect the 1 bit that turns a thing on or off.
Protection against: Replay, alteration, spoofing and provide authentication within the bounds of symmetric cryptography. Hiding the content is a secondary objective, which can be enabled if needed.
The CP uses AES, AES-CMAC cryptographic primitives. An additional permutation is used to change the position of bytes with in the 80 byte encrypted message.Attached below is a rewrite of the server code previously posted. It encapsulates the server into an object.
-
Postw6.js 2 Sep 2016
This code encapsulates into objects and eliminates global variable, except for the configuration variables. It uses emit() and object.on() functions to signal that the WiFi is connected. The console is redirected so that a menu system appears on the USB port.
The Hardware variable selects PICO or Espruino board hardware connected to an ESP8266.
Select Espruino Bd or Pico hardware
var Hardware=0; //Espruino board
var Hardware =1; //PICO
The IP variable contains the IP address of the server
//setup IP address of server
IP="192.168.1.5";
The SSID and key variables identify the WiFi router acces information
//setup WiFi access parameters
var SSID="router name";
var key= "router key";
Start the HTMLserverA1.js
The output:>echo(0); =undefined -> LoopbackB Select using digit and return key 1 Connect 0 Exit <- USB >1 do connect Start connection process Waiting for ESP8266 response Reset the ESP8266 Connecting to WiFi Wi-Fi Connected Select using digit and return key 1 Good Message 2 Bad Message 0 Exit IP= 192.168.1.4 null 1 Send Good Message 80 192.168.1.5 send Closed: 01234567890123456789012345678901234567890123456789012345678901234567890123456789 ss 01234567890123456789012345678901234567890123456789012345678901234567890123456789 Select using digit and return key 1 Good Message 2 Bad Message 0 Exit 2 Bad Message 70 192.168.1.5 send Closed: 1234 ss 1234 Select using digit and return key 1 Good Message 2 Bad Message 0 Exit 0 Exit <- LoopbackB =undefined =undefined >USB.setConsole(); -> USB
-
Great work!
I've always wanted to use this kind of display ever since the Kindle came out.
A bit disappointed on the lower end of it's temperature range.You might use this module to store the fonts in EEROM on the chip.
http://www.espruino.com/FlashEEPROM
Some code examples using arrays are discussed here.
http://forum.espruino.com/conversations/292062/ -
All this is basic work for the Cryptographic Protocol on a PICO project.
This project needs a way to post 80 character messages and reply with the same.
http://forum.espruino.com/conversations/291068/It is posted as a separate project as it may have use in other projects without being entangled in the cryptography.
The Server
htmlServerA1.js 1 Sep 2016
for use with a PICO or espruino board with ESP8266
When executed if IP=192.168.1.5, use the following in the browser
//http://192.168.1.5:8080/
And use IP="192.168.1.5"; in Postw4.js
Configure the following:
//Flag to test with browser controls the HTML page that is served to a browser
//var Bflag=0; //use with kryptomessage,js
var Bflag=1; //test with browesr
//Select the hardware options
//var Hardware=0; //Espruino board
var Hardware =1; //PICO
//Set up access to wifi router
var SSID="router name";
var key= "router key";
The output of htmlServerA1.jsecho(0); Start Start connection process Try again =undefined Reset the ESP8266 Connecting to WiFi Wi-Fi Connected IP= 192.168.1.5 Null
Use a browser and point it to http://192.168.1.5:8080/
You will get one of two html pages depending on the Bflag setting.
If you set Bflag=1 the page will contain a title, and three buttons.
The bad button posts 70 characters and returns “1234”.
The good button posts 80 characters and returns all 80 characters.
Postw4.js simply does the post.
Postw4.js 1 Sep 2016
This does a POST to the server running on another device.
Use with PICO or espruino board with ESP8266.
You will need to configure the following parameters.
setup IP address of server
IP="192.168.1.5";
//Select length of message
var clength=8; //good
//var clength=7; //bad
// Select Espruino Bd or Pico hardware
//var Hardware=0; //Espruino board
var Hardware =1; //PICO
//setup WiFi access parameters
var SSID="wifi router name";
var key= "wifi key";Output with clength=8
>echo(0); Start Start connection process Waiting for ESP8266 response =undefined Reset the ESP8266 Connecting to WiFi Wi-Fi Connected 80 IP= 192.168.1.4 null send Closed: 01234567890123456789012345678901234567890123456789012345678901234567890123456789
-
Unionized arrays anyone?
//ArrayTrick1.js //30 Aug 2016 //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer var f = new (require("FlashEEPROM"))(); var buff = new ArrayBuffer(16); var view = new Int32Array(buff); for(var i=0;i<4;i++)view[i]=i*256*256*256+i*100; //buff and view are unionized console.log("buff= ",buff); console.log("view= ",view); buff[0]=5; console.log("buff= ",buff); console.log("view= ",view); console.log("write to ROM"); f.write(21,JSON.stringify(btoa(buff))); console.log("read from ROM"); var H=new Int32Array(E.toArrayBuffer(atob(JSON.parse(E.toString(f.read(21)))))); console.log("H= ",H);
The output:
ent>echo(0); buff= new ArrayBuffer([0, 0, 0, 0, 100, 0, 0, 1, 200, 0, 0, 2, 44, 1, 0, 3]) view= new Int32Array([0, 16777316, 33554632, 50331948]) buff= new ArrayBuffer([5, 0, 0, 0, 100, 0, 0, 1, 200, 0, 0, 2, 44, 1, 0, 3]) view= new Int32Array([5, 16777316, 33554632, 50331948]) write to ROM read from ROM H= new Int32Array([5, 16777316, 33554632, 50331948])er code here
-
So I tried an array of 15 length and it works.
This version adds another step to do Uint16Array.console.log("Add this step to convert Uint16Array to Uint8Array"); A.C = new Uint8Array(A.C.buffer); //the trick console.log("apply btoa trick"); A.C=btoa(A.C); console.log("A= ",A);
and
//the trick in reverse console.log("reverse the trick"); H.C=E.toUint8Array(atob(H.C)); console.log("H= ",H); console.log("Convert H.C back to Uint16Array"); H.C= new Uint16Array(H.C.buffer); console.log("H16= ",H);
The output:
>echo(0); Create an object with an Uint16Array A= { "B": 1240, "C": new Uint16Array([0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400]) } Stringify the object D= {"B":1240,"C":new Uint16Array([0,100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400])} Parse it back returns undefined F= undefined Add this step to convert Uint16Array to Uint8Array apply btoa trick A= { "B": 1240, "C": "AABkAMgALAGQAfQBWAK8AiADhAPoA0wEsAQUBXgF" } stringify D= {"B":1240,"C":"AABkAMgALAGQAfQBWAK8AiADhAPoA0wEsAQUBXgF"} Write D to flash Read G from flash G= new Uint8Array([123, 34, 66, 34, 58, 49, 50, 52, 48, 44, 34, 67, 34, 58, 34, 65, 65, 66, 107, 65, 77, 103, 65, 76, 65, 71, 81, 65, 102, 81, 66, 87, 65, 75, 56, 65, 105, 65, 68, 104, 65, 80, 111, 65, 48, 119, 69, 115, 65, 81, 85, 66, 88, 103, 70, 34, 125]) parse G into H H= { "B": 1240, "C": "AABkAMgALAGQAfQBWAK8AiADhAPoA0wEsAQUBXgF" } reverse the trick H= { "B": 1240, "C": new Uint8Array([0, 0, 100, 0, 200, 0, 44, 1, 144, 1, 244, 1, 88, 2, 188, 2, 32, 3, 132, 3, 232, 3, 76, 4, 176, 4, 20, 5, 120, 5]) } Convert H.C back to Uint16Array H16= { "B": 1240, "C": new Uint16Array([0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400]) }
Anyone want to try Uint32Array?
-
An object containing a Unit8Array is written to flash and read back again.
I think I read somewhere thatthe atob and btoa functions operate on 4 byte increments and you have to pad the length to a integer multiple of 4.
var A=new Uint8Array(8) will work. var A=new Uint8Array(7) won't.
Give it a try anyway.console.log("Create an object with an Uint8Array"); var A={B:10,C:new Uint8Array(16)}; for(i=0;i<16;i++)A.C[i]=i; console.log("A= ",A);
The output:
>echo(0); Create an object with an Uint8Array A= { "B": 10, "C": new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) } Stringify the object D= {"B":10,"C":new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])} Parse it back returns undefined F= undefined apply btoa trick A= { "B": 10, "C": "AAECAwQFBgcICQoLDA0ODw==" } stringify D= {"B":10,"C":"AAECAwQFBgcICQoLDA0ODw=="} Write D to flash Read G from flash G= new Uint8Array([123, 34, 66, 34, 58, 49, 48, 44, 34, 67, 34, 58, 34, 65, 65, 69, 67, 65, 119, 81, 70, 66, 103, 99, 73, 67, 81, 111, 76, 68, 65, 48, 79, 68, 119, 61, 61, 34, 125]) parse G into H H= { "B": 10, "C": "AAECAwQFBgcICQoLDA0ODw==" } reverse the trick H= { "B": 10, "C": new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) }
-
Try this exercise:
//Uint8Trick.js //30 Aug 2016 var i; console.log("Create an object with an Uint8Array"); var A={B:512,C:new Uint8Array(16)}; for(i=0;i<16;i++)A.C[i]=i; console.log("A= ",A); console.log("Stringify the object"); var D=JSON.stringify(A); console.log("D= ",D); console.log("Parse it back returns undefined"); var F=JSON.parse(D); console.log("F= ",F); //F is undefined //notice I skipped E to avoid conflict with E.toUint8Array //the trick console.log("apply btoa trick"); A.C=btoa(A.C); console.log("A= ",A); console.log("stringify"); var D=JSON.stringify(A); console.log("D= ",D); console.log("parse"); var F=JSON.parse(D); console.log("F= ",F); //the trick in reverse console.log("reverse the trick"); F.C=E.toUint8Array(atob(F.C)); console.log("Frev= ",F);
and the output
>echo(0); Create an object with an Uint8Array A= { "B": 512, "C": new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) } Stringify the object D= {"B":512,"C":new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])} Parse it back returns undefined F= undefined apply btoa trick A= { "B": 512, "C": "AAECAwQFBgcICQoLDA0ODw==" } stringify D= {"B":512,"C":"AAECAwQFBgcICQoLDA0ODw=="} parse F= { "B": 512, "C": "AAECAwQFBgcICQoLDA0ODw==" } reverse the trick Frev= { "B": 512, "C": new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) } =undefined
-
getDweet.js 20 Aug2016
Incorporates the Dweet example into code that connects the ESP8266 to WiFi.
Setup parameters at the beginning of the code://set DweetID to a unique value var DweetID="esp0912"; // Select Espruino Bd or Pico hardware //var Hardware=0; //Espruino board var Hardware =1; //PICO //setup WiFi access parameters var SSID="xxxx"; var
On the IOT page
http://www.espruino.com/IoT+Services
the link “quite a lot” returns a “Nothing out there” error
http://www.postscapes.com/companies/iot-cloud-servicesOutput of getdweet.js
>echo(0); Start Start connection process Waiting for ESP8266 response =undefined Reset the ESP8266 Connecting to WiFi Wi-Fi Connected IP= 192.168.1.4 null put res.headers { "Access-Control-Allow-Origin": "*", "Content-Type": "application/json", "Content-Length": "197", "Date": "Tue, 30 Aug 2016 16:49:56 GMT", "Connection": "close" } {"this":"succeeded","by":"dweeting","the":"dweet","with":{"thing":"esp0912","created":"2016-08-30T16:49:56.321Z","content":{"hello":"world99"},"transaction":"176f2d59-c8ff-4166-97e7-4ebaa01c3064"}} get res.headers { "Access-Control-Allow-Origin": "*", "Content-Type": "application/json", "Content-Length": "146", "Date": "Tue, 30 Aug 2016 16:49:56 GMT", "Connection": "close" } { "hello": "world99" }
Note that the data are appended to the URL in the putDweet() function.
var options = { host: 'dweet.io', port: '80', path:'/dweet/for/'+dweet_name+"?"+data, method:'POST' };
But in the Cubitic example the data (content) is not added to the end of the URL in the header but is sent after the header in the last line the function by the function call end(content).
function putCubitic(event, data) { content = JSON.stringify(data); var options = { host: 'api.cubitic.io', port: '80', path:'/v1/event/'+event, method:'POST', headers: { "Content-Type":"application/json", "cubitic-appid":CUBITIC.APPID, "Authorization":"Bearer "+CUBITIC.TOKEN, "Content-Length":content.length } }; require("http").request(options, function(res) { var d = ""; res.on('data', function(data) { d+= data; }); res.on('close', function(data) { console.log("Closed: "+d); }); }).end(content); }
This might help.
http://forum.espruino.com/conversations/286139/#comment12965959
The syntax is different on different implementations for some reason.