-
httptohttps is now live again at HttpToHttps.MrTimcakes.com
-
Ah, and about using an ESP over the Orginal Espruino. Originally I wanted to use an ILI9341 LCD and display multiple graphs at the same time, this is why I designed the Graph library to create new instances. However, I couldn't get the display to update fast enough. Perhaps I'll try to improve that again at some point, probably something to do with compiled code for the STM32, any advice for that is welcome. In the end seeing as though I was going to use an OLED anyway it was easier to just use a NodeMCU.
-
And here is Graph.js
/* Copyright (c) 2017 MrTimcakes. See the file LICENSE for copying permission. */ /* Live graphs that update from right to left var Graph = require("graph"); var myGraph = new Graph(90, 48); myGraph.initData([0,1,2,3,4,5,10,15,20,25,30]); function draw(){ g.clear(); myGraph.drawGraph(g, 5, 5); g.flip(); } */ /* Create new graph, datapoints to keep (width), height, range of data from 0 */ function Graph(historyLength, height = 64, range = 100) { this.history = new Int8Array(historyLength); this.height = height; this.range = range; } Graph.prototype.setHeight = function(height) { this.height = height; }; Graph.prototype.setRange = function(range) { this.range = range; }; /* Cycle all history values, add new ones to the end*/ Graph.prototype.update = function(data) { for (var i=1;i<this.history.length;i++){ this.history[i-1] = this.history[i]; } this.history[this.history.length-1] = data; }; /* Replace end of history with the array given */ Graph.prototype.initData = function(data) { if(Array.isArray(data)){ for (var i=0;i<data.length;i++){ this.history[this.history.length-i] = data[data.length-i]; } } }; /* Draw axis, the convert each value to a y and plot */ Graph.prototype.drawGraph = function(g, x, y) { g.drawLine(x, y, x, y+this.height); g.drawLine(x, y+this.height, x+this.history.length, y+this.height); g.moveTo(x, (y - (this.height/this.range)*this.history[0]) + this.height); for (i=1;i<this.history.length;i++){ g.lineTo(x+i, (y - (this.height/this.range)*this.history[i]) + this.height); } }; exports = Graph;
-
I've often wanted to know the CPU utilization of my home server to help debugging or just seeing general usage, I'm aware of the Pico CPU Monitor but that uses USB, seeing as though it's a server I wanted something with WiFi. Oh and fancy WebSockets.
First of all, we need some software on the server to broadcast its utilization. I chose WebSocketd, it takes any regular command line script and broadcasts it over WebSockets. Just remember to add it to your $PATH so you can use it from anywhere. I thought this was easier than making Node script to do essentially the same thing, this project is about Espruino after all. I have this run in a screen at startup on my server:
websocketd --port=9231 /usr/bin/vmstat -n 1
Now for the Espruino portion, while I had originally planned to run this on an Original Espruino I ended up using an ESP8266 I'll explain why later. The Espruino has to connect to the server, parse the information then display it on a graph. The information from the WebSocket comes in a format structured for columns on a command line using multiple spaces to separate it. Since Espruino doesn't support RegEx yet I had to use some fidgeting with indexOf to get the data into a usable format, specifically the idle time of the CPU. I then created a simple graph library to convert the CPU utilization into a graph and plot it. I used an SSD1306 128*64 OLED, here's the code and how it looks:
require("Font8x12").add(Graphics); I2C1.setup({scl:NodeMCU.D4,sda:NodeMCU.D3}); var Wifi = require("Wifi"); var Graph = require("http://dev.mrtimcakes.com/espruino/graph.js"); var CPU = new Graph(90, 48); var WebSocket = require("ws"); var ws = new WebSocket("<YOUR SERVER HERE>",{port: 9231, origin: 'http://' + Wifi.getIP().ip}); var column = ["r", "b", "swpd", "free", "buff", "cache", "si", "so", "bi", "bo", "in", "cs", "us", "sy", "id", "wa", "st"]; var lastUpdate = 0; ws.on('message', function(e) { while(e.indexOf(' ')!=-1)e=e.replace(' ',' '); var raw = e.trim().split(" "); var data = {}; for (var i = 0; i < column.length; i++) { data[column[i]] = parseInt(raw[i]); } CPU.update(100 - data.id); lastUpdate = getTime(); }); function draw(){ g.clear(); g.setFont8x12(); g.drawString("CPU", 7.5, 27); CPU.drawGraph(g, 33, 5.5); g.setFontBitmap(); g.drawString("0", 29, 48); g.drawString("100", 21, 6); g.drawString("0", 33, 55); g.drawString("90", 115, 55); g.drawString("Seconds", 64, 55); if( (getTime() - lastUpdate) > 1.5){ g.drawString("!", 0, 0); } g.flip(); } var g = require("SSD1306").connect(I2C1, function(){ draw(); setInterval(draw,1000); });
-
@Gordon Alas, I don't. I run it from a server machine at home, I never really set-up logging, I just checked through the logs I do have but because of the way I have it setup I couldn't determine what was for the HttpToHttps service, I don't imagine it was a whole lot though.
What I imagine I'll do is continue the service, but under a subdomain of my personal domain which I plan to keep for the foreseeable future as I don't want to renew the xyz domain, as my graphics card just died. Isn't student life fun xD. The new domain will be something like "HTH.MrTimcakes.com" or "HttpToHttps.MrTimcakes.com" once I get round to moving it.
-
Alright, I've put the code on GitHub whether or not I decide to keep the domain.
-
Does anyone actually use HttpToHttps.xyz? Just that the domain expires on Jun 12, 2017, wondering if I should renew it. @MaBe Do you use it?
-
Just curious for this phantom nRF52 based Pico, for those who don't have any desire to use BLE would there be any tangible benefit to have a build of Espruino that doesn't include any of the BLE?
Also, why not make an Espruino board based off an ESP32 its got BT,BLE and WiFi. Wait never mind, you putting all that work into a product just to have consumers flash it onto cheap Chinese boards instead of buying the official doesn't make a lot of business sense.
-
Very strange to hear that the WebIDE is causing you issues, in my expericnes its very reliable. However if you wish to, you can use the Espruino NPM Module and set it to watch a file, then you can use Sublime Text to exit a local JS file and every time you save it, it will be sent to the Espruino.
You could also try to use the WebIDE as a native windows program, here's where to get it.
-
Perhaps this post could be useful to you, there are also instructions for the SSD1306 just below.
-
@CanyonCasa I could be totally wrong here, but from the way @urbiman said "bake javascript into the firmware" leads me to believe he wants to compile a binary of Epruino with some javascript embedded so when he flashes it to a chip it already has the code on it and doesn't need to then be programmed by the WebIDE. Though I could be wrong.
-
Hey, You shouldn't need to add anything to the code to make it print the message to the console, the
ws.on('message',function(msg) { print("[WS] "+JSON.stringify(msg)); });
line does that. However, perhaps you need to JSON.stringify it first.
I just pasted the code I posted above your comment and put it on my ESP, connected and it worked perfectly from both my desktop Chrome, and my Android Chrome. Perhaps you have an out of date web-browser that doesn't support web-sockets? -
Just gonna do some self-endorsement here, you could try using HttpToHttps like in this post.
-
JavaScript in the browser handles multiple threads of JavaScript via Web-Workers, perhaps there could be an implementation like that?
-
The watch I ordered arrived sooner than expected. As I expected the watch doesn't contain a nRF51, it actually uses a Dialog DA14580, we've seen this chip before in this thread. So no Espruino, but, this one does actually pair to my phone. I took some pictures while deconstructing it, I could post them if anyone is interested on how the Heart Rate sensor connects.
-
Yeah that works no problem, after I added custom header support ;)
I̶t̶ ̶s̶h̶o̶u̶l̶d̶ ̶w̶o̶r̶k̶ ̶w̶i̶t̶h̶ ̶h̶t̶t̶p̶.̶r̶e̶q̶u̶e̶s̶t̶ ̶b̶u̶t̶ ̶I̶ ̶c̶a̶n̶'̶t̶ ̶g̶e̶t̶ ̶a̶n̶y̶ ̶f̶o̶r̶m̶ ̶o̶f̶ ̶t̶h̶a̶t̶ ̶t̶o̶ ̶w̶o̶r̶k̶,̶ ̶e̶v̶e̶n̶ ̶i̶f̶ ̶t̶h̶e̶r̶e̶ ̶i̶s̶n̶'̶t̶ ̶a̶n̶y̶ ̶c̶u̶s̶t̶o̶m̶ ̶h̶e̶a̶d̶e̶r̶s̶.̶
And ready for Espruino here you go:
var options = { host: 'httptohttps.xyz', path: '/https://api.fencer.io/v1.0/geofence', method: 'GET', headers: { "Authorization" : "YOUR-KEY-HERE" } }; require("http").get(options, function(res) { var contents=""; res.on('data', function(data) { console.log(data); }); res.on('close', function(data) { console.log("Connection closed"); }); });
Something strange happens if I try add data to contents though, it just returns false, that's why I thought I couldn't get it to work.
-
@Wilberforce I don't think the 2nd "install" in sudo apt-get install gcc-arm-none-eabi git install build-essential should be there should it?
-
Does this update just let you use Bash inside the command prompt? If so, I think you could also install Git and select "Use Git and optional Unix tools from the windows command prompt" during the installation which will allow them to run this bash script just like in Linux.
-
@Gordon Thanks, I sent the ebay seller a message asking if he could confirm that it is in-fact an nRF51, they said it is. Now just to wait, oh and to find my SWD Programmer :p
-
-
This bracelet looks interesting. It's got a heart rate monitor and advertises "CPU: nRF51822" in the description, I meant I don't trust it, but Imma try it anyway, it also has a much better strap. I'll post results when it arrives.
-
-
@user67183 Not sure if it's just me, but some of your Inline Images don't work.
-
You could try getting one of those cheap Smart Bracelets and flashing Espruino on it like on this post though it is likely that you'll receive something very slightly different with a chip that Espruino doesn't support :(
I've tried this before and been unlucky, but soon I'll be trying it again, I'll probably buy this one.
Yeah, is 10MHz the fastest SPI clock? The Adafruit ILI9341 and TFT_eSPI Arduino libraries run 36MHz for the STM32F1 and 40MHz for the ESP