Hack it – layer zero labs https://l0l.org.uk.archived.website make it, break it, fix it, hack it, own it Sun, 24 May 2015 10:29:59 +0000 en-GB hourly 1 https://wordpress.org/?v=4.5.14 Idle Timeout in Express https://l0l.org.uk.archived.website/2015/02/idle-timeout-express/ https://l0l.org.uk.archived.website/2015/02/idle-timeout-express/#respond Tue, 03 Feb 2015 18:04:17 +0000 https://l0l.org.uk.archived.website/?p=696 Idle Timeout was not possible in express sessions until recently. You could set maxAge on the session’s cookie, but that would make the cookie expire after the given time regardless of activity. But it is more usual to want to expire the session after a certain amount of time with no activity. That is now possible […]

The post Idle Timeout in Express appeared first on layer zero labs.

]]>
Idle Timeout was not possible in express sessions until recently. You could set maxAge on the session’s cookie, but that would make the cookie expire after the given time regardless of activity. But it is more usual to want to expire the session after a certain amount of time with no activity. That is now possible with the rolling option.

Suppose you want to log users out automatically if they haven’t used your app for half an hour. You can do this with the following settings:

var idleTimeoutSeconds = 1800;

app.use(session({
resave: true,
cookie: {
maxAge: idleTimeoutSeconds * 1000,
},
rolling: true,

// … the rest of your options

}));

The rolling option is documented here but there’s a gotcha which is not mentioned: you have to set resave to true. It’s not obvious why this would be the case, since even without resave the session data is saved on change, and the rolling option appears to produce a change in the session upon every request. But without resave: true, I found that the session was expiring after the given time regardless of activity.

The post Idle Timeout in Express appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2015/02/idle-timeout-express/feed/ 0
ESP8266 modules hardware guide – gotta catch ’em all! https://l0l.org.uk.archived.website/2014/12/esp8266-modules-hardware-guide-gotta-catch-em-all/ https://l0l.org.uk.archived.website/2014/12/esp8266-modules-hardware-guide-gotta-catch-em-all/#comments Fri, 05 Dec 2014 13:46:31 +0000 https://l0l.org.uk.archived.website/?p=618 OK so there is this new(ish) chip the ESP8266EX that promises a full wifi stack and a mcu all for £2-3. But the chip on it’s own isn’t so useful – so most of the excitement has been around the various modules made with the chip, some memory and an antenna or connector for one. […]

The post ESP8266 modules hardware guide – gotta catch ’em all! appeared first on layer zero labs.

]]>
OK so there is this new(ish) chip the ESP8266EX that promises a full wifi stack and a mcu all for £2-3. But the chip on it’s own isn’t so useful – so most of the excitement has been around the various modules made with the chip, some memory and an antenna or connector for one. Unfortunately there is a lot of diversity, modules being revised and so on – which makes choosing one of these modules quite difficult. Here I’ve tried to bring together all the info I could about these different modules to help you choose which one fits your needs best. If you have any information about these modules then please leave a comment and I’ll incorporate it! The modules have attracted the codes ESP-01 through ESP-12 – this document in Chinese and this webshop catalog formed the starting point. The ESP8266.com community and Squonk, shekel, TuxFanGKR and others deserve credit for gathering most of this infomation here.

espfront
front of ESP modules ESP-01 through ESP-11
espback
back of ESP modules ESP-01 through ESP-11

The basic attributes of these modules are as follows:

Modules

Dimensions

Picture

Pinout

Antenna

GPIO

Notes

ESP-01 14.3mmx24.8mm ESP 01 Module photo variant 1 ESP-01 Modules pinout variant 1 PCB Antenna GPIO0/2/16 Multiple Variants Exist! Most common module. This version may be known as V090 or V091
ESP-02 14.2mmx14.7mm ESP-02 Module photo variant 1 ESP-02 Modules pinout variant 1 U-FL connector GPIO0/2/15 Multiple Variants Exist!
ESP-03 17.4mmx12.2mm ESP-03 Module photo ESP-03 Module pinout Ceramic Antenna GPIO0/2/12/13/14/15/16 Most popular in esp8266.com poll
ESP-04 14.7mmx12.1mm ESP-04 Module photo ESP-04 Modules pinout none GPIO0/2/12/13/14/15/16
ESP-05 14.2mmx14.2mm ESP-05 Module photo variant 1 ESP-05 Modules pinout variant 1 U-FL connector NONE Multiple Variants Exist!
ESP-06 14.2mmx14.7mm ESP-06 Module photo ESP-06 Modules pinout None GPIO0/2/12/13/14/15/16 Metal shield claims FCC
ESP-07 22mmx16mm ESP-07 Module photo ESP-07 Modules pinout Ceramic Antenna & U-FL connector GPIO0/2/4/5/12/13/14/15/16 Multiple Variants Exist! Metal shield claims FCC
ESP-08 17mmx16mm ESP-08 Module photo ESP-08 Modules pinout None GPIO0/2/12/13/14/15/16 Metal shield claims FCC
ESP-09 10mmx10mm ESP-09 Module photo ESP-09 Modules pinout None GPIO0/2/12/13/14/15 1MB Flash memory
ESP-10 14.2mmx10mm ESP-10 Module photo ESP-10 Modules pinout None None
ESP-11 19.3mmx13mm ESP-11 Module photo ESP-11 Modules correct pinout Ceramic Antenna GPIO0/1
ESP-12 24mmx16mm ESP-12 Module photo ESP-12 Modules pinout PCB Antenna ADC + GPIO0/2/4/5/12/13/14/15/16 Metal shield claims FCC
DWA8 17mmx27.1mm DWA 08 Module photo DWA 08 Module pinout PCB Antenna ADC + GPIO0/2/12/13/14/15/16

ESP-01 Variants:

Tinhead of the esp8266.com community contributed info about an older variant using the ESP8266 rather than ESP8266EX (may also be referred to as v080):

ESP-01 Module photo variant 2 frontESP-01 Module photo variant 2 backESP-01 Modules pinout variant 2

ESP-02 Variants:

TuxFanGKR of the esp8266.com community reported that a pinout variant had made him let the magic smoke out! And a third variant (confusingly named ESP-02 version 2) has been spotted here. Pinout is of TuxFanGKR’s variant – photo of ‘version 2’.

ESP-02 Modules pinout variant 2ESP 02 Module photo variant 3

ESP-05 Variants:

A fifth pin has been added to the ESP-05 module carrying reset, thanks to esp8266.com contributors gbit and Didier9 for this info:

ESP 05 Module photo variant 2ESP-05 Modules pinout variant 2

 

ESP-07 Variants:

A variant of the ESP-07 has been reported with 2 extra connections (one of them ADC) by mvdlande on the esp8266.com forum:

ESP 07 Module photo variant 2

References:
ESP8266EX Pinout
Hardware guide

Any corrections, omissions or improvements? Please leave a comment!
Thanks to comment below, pinout of module ESP-11 has been corrected.

The post ESP8266 modules hardware guide – gotta catch ’em all! appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2014/12/esp8266-modules-hardware-guide-gotta-catch-em-all/feed/ 45
Squatconf Presentation https://l0l.org.uk.archived.website/2014/11/squatconf-presentation/ https://l0l.org.uk.archived.website/2014/11/squatconf-presentation/#respond Sat, 15 Nov 2014 16:16:02 +0000 https://l0l.org.uk.archived.website/?p=601 We’re at SquatConf. It’s amazing! All conferences should be in squats. (Ones that serve good quality beer on draft, in particular. And where you can have  a cigarette while you’re presenting). Here are the slides for the presentation we just gave. And here’s our alternative translation of the heart sutra (now on Github!) Avalokitesvara the Origin Mistress […]

The post Squatconf Presentation appeared first on layer zero labs.

]]>
We’re at SquatConf. It’s amazing! All conferences should be in squats. (Ones that serve good quality beer on draft, in particular. And where you can have  a cigarette while you’re presenting).

Here are the slides for the presentation we just gave. And here’s our alternative translation of the heart sutra (now on Github!)

Avalokitesvara the Origin Mistress
when debugging deeply the Undefined Paramita
perceives that all of the log files are empty
and is saved from all suffering and distress.

Oh Javascript Programmer,
objects do not differ from null,
null is merely a kind of object.
Undefined is a function,
and all functions are undefined.
The same is true of strings,
integers, arrays, truth or falsehood.

Programmer,
the features of Javascript are also its bugs;
never released and never abandoned,
neither supported or unsupported,
neither maintained nor deprecated.
Therefore, in Javascript no bugs, features,
commits, reverts, authors.

No types, no classes, no entities, no attributes,
no private, no public, no package, no friends,
no runtime context;
no state or scope
and so forth until no realm of computation.

No errors and also no catching of errors,
and so forth until no breaking or crashing
and no end of crashing and breaking.

Nothing synchronous, nor asyncronous,
no pushing no popping, no heap no stack
also no returning with nothing to return.

The Origin Mistress accepts the Undefined Paramita
and logic is no hindrance.
without any logic no programs exist.
Realising this, good code is created.
(So good, it even runs in Internet Explorer.)

In the three browsers
all Programs depend on Undefined Parameters,
on Max that is less than Min, and the Number that Not a Number.

Therefore know that the Undefined Parameter
is the great transcendent mantra,
is the great bright mantra,
is the utmost mantra,
is the supreme mantra
which is able to relieve all suffering
and is truthy, insofar as it is not falsey.

So proclaim the Undefined Paramita mantra,
proclaim the mantra which says:
Object does not support this property or method.

 

The post Squatconf Presentation appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2014/11/squatconf-presentation/feed/ 0
Open aquaponics API, documented with Swagger and sample app https://l0l.org.uk.archived.website/2014/08/open-data-api-documented-swagger-sample-app-github-natch/ https://l0l.org.uk.archived.website/2014/08/open-data-api-documented-swagger-sample-app-github-natch/#respond Thu, 07 Aug 2014 17:11:54 +0000 https://l0l.org.uk.archived.website/?p=539 We’re proud to release the first public iteration of our Aquaponics Open Data API. You can see it live here – and we are very keen to get feedback, suggestions, improvements and collaborators in true open-source fashion. Our goal is to allow others to write applications to use data from our systems for their own purposes, as well as reusing […]

The post Open aquaponics API, documented with Swagger and sample app appeared first on layer zero labs.

]]>
We’re proud to release the first public iteration of our Aquaponics Open Data API. You can see it live here – and we are very keen to get feedback, suggestions, improvements and collaborators in true open-source fashion.

Aquaponics API
Swagger documentation of our Aquaponics API

Our goal is to allow others to write applications to use data from our systems for their own purposes, as well as reusing our API and apps themselves. The API is documented using the fabulous Swagger specification – we used the swagger-node-express because we like node. Swagger provides great looking documentation of the API as well as full details of the responses and error codes, but wait – there’s more. It’s not documentation in the usual sense, it’s an interface to the API itself. Thus it provides a really easy way to test the API out and get real data back, complete with headers and response codes – everything you need to develop apps against it.

Our system uses the seriously hard-core Cassandra database – even though we can’t quite justify it based on our data-needs today! In fact when we asked a support question on the Cassandra IRC channel we were told that a mere two box cluster was ‘not a typical deployment’! But it fits our requirements in terms of storing time-series data – and we have great hopes that soon we’ll be needing racks of boxes across several continents. If it’s good enough for GitHub and CERN then it’s good enough for us.

Speaking of GitHub, all our code are belong to you – this means it’s released under the GPL v2 and you’re welcome (and obligated!) to use it, abuse it, improve it and then return those improvements back to the common pot.

As well as all of this, we’ve also written an app that uses our API to present a simple web form allowing for the download of data in csv format. You can try out our download app here – again we really do appreciate your feedback (it’s the best way to get better).

Download as CSV web app
Download aquaponics data as CSV

Node express allowed us to get this simple web-app up and running with the minimum of fuss and maximum of effect. We’re hoping to follow this up with a graphing app very soon – watch this space.

We’ll be showcasing the system and its associated API , apps and dashboard at the very wonderful Wuthering Bytes open hardware festival in Hebden Bridge – if you can possible be there – you must! As well as our talk/workshop there are dozens of great things happening from Sophie Wilson to space rocket launches and beyond!

The post Open aquaponics API, documented with Swagger and sample app appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2014/08/open-data-api-documented-swagger-sample-app-github-natch/feed/ 0
Wireless pH sensor https://l0l.org.uk.archived.website/2014/05/wireless-ph-sensor/ https://l0l.org.uk.archived.website/2014/05/wireless-ph-sensor/#comments Thu, 22 May 2014 12:50:10 +0000 https://l0l.org.uk.archived.website/?p=515 JeeNode + MinipH + LiPo + Case = Wireless pH sensor This sensor is probably the one I’m most proud of so far, all the elements came together really well despite having to hack the MinipH circuit in the literal sense! The enclosure maketh the project As soon as I had finished making this sensor, […]

The post Wireless pH sensor appeared first on layer zero labs.

]]>
JeeNode + MinipH + LiPo + Case = Wireless pH sensor
wireless pH sensor
wireless pH sensor

This sensor is probably the one I’m most proud of so far, all the elements came together really well despite having to hack the MinipH circuit in the literal sense!

The enclosure maketh the project

As soon as I had finished making this sensor, and put the lid on and stepped back, I was genuinely surprised and pleased with how much better the sensor suddenly seemed. Despite the fact that I knew exactly how much sweat and tears had been expended and all the clever details, even then, I was mostly impressed when the case went together!!

At first I was a bit disconcerted by this, I am constantly trying to see the ‘real substance’ of things, ideas and people, rather than just see the ‘surface’ details. And yet, even with a project of my own that I knew intimately, I was beguiled by the case.

So anyway, the case turned out to be the perfect size, the quality of the plastic (ABS) and surface finish is very good, the sides feel strong and mate well with each other. It’s made by Evatron, model PC001 and I ordered a black and white one, both with and without a battery compartment from CPC in the UK (£4.54 with free delivery).

I prefer the look of the white one, its not trying to be Apple white (they’ve probably patented that one) but it’s not beige either – I suppose ivory is a fair description. The battery compartment option tempted me but I decided in the end that it would never be moisture or splash-proof let alone waterproof with a door.

Construction details

Inside the pH sensor
Inside the pH sensor

One of the first and easiest decisions was to remove some of the little plastic mounts intended for internal pcbs, they just get in the way. I snipped most of them off with heavy duty wire cutters and then used a sharp chisel to cut the remains of the plastic flush to the surface. Then the hole can be made in the middle of an end, it needs to be 12mm to accomodate the BNC connector of the pH pH probe circuit. I find that it’s very difficult to drill holes accurately without a pillar drill, especially in this sort of situation where the hole needs to go in the middle of where the case splits. However, it is perfectly possible to mark out pretty accurately by careful measurement and ‘eyeing’ up the marks from several angles. So I just marked out the hole as carefully as I could, then drilled it roughly in the middle at 10mm. I then used a file to remove the rest of the material and return the hole to a centred circle. I tried to retain a flat on one side of the hole, to match the mounting pattern of the connector, but it’s not vital.

Now in order to fit the pH sensor circuit we need to hack it – this time with a fine hacksaw. I spend quite a few minutes examining the board layout files (yet another reason to love open source hardware!) and a load more time examining the physical circuit, and became convinced that there weren’t any traces or components that I’d be damaging. The physical construction of this type of circuit is important, but I reassured myself that I wouldn’t be breaking any guard traces, just clipping off a bit of ground plane.

MinipH circuit cut to fit case
MinipH circuit cut but unblodied

Needless to say, despite my brave words I was more than a bit apprehensive to take a hacksaw to such a perfectly formed little board. Perhaps this is what novice surgeons feel the first few times they have to cut into somebody? Anyway the operation was a success, and the patient was able to make a full recovery, minus a corner.

The MinipH circuit is from Sparky’s Widgets – aka Ryan Edwards – another hacker hero of mine! (I think I’m going to have to make a page of them soon). He has some great info on his site that really helped me understand some of the more subtle aspects of pH measurement.

I decided to use the hardware I2C port rather than the software ports provided as part of JeeLib – I figured that perhaps the processing overhead might be a bit lower, but I haven’t tested that assumption. The demo sketch provided with the hardware worked great out of the box, and Naomi then wrapped it in a class and got the data sent over the radio.

The only other fiddly detail was getting the power consumption down, as the circuit consumes a few milliamps constantly. I tried a few different ways to power the circuit and eventually settled on using a digital out to raise vcc high when I need it. The draw of the circuit is well inside the limits for the IO pins, and it seems to work fine. This way I can sleep most of the time and only switch on the sensing circuit when required.

I did some testing and found that the pH circuit needs quite a bit of time to settle, and I ended up allowing five seconds for the circuit to ‘warm up’ before reading from it. Even then the results often carry on dribbling up (or down) for quite a while. So rather than a pattern of ‘wake up, measure, sleep’ that we’re currently using, in the future we’ll be implementing a scheme where the sensor wakes up, keeps the pH circuit powered up for some time whilst taking measurements, then sleeps. Of course the mcu/radio can be sleeping during most of the measurement time, but the sensor would remain powered up.

In an ideal world I’d like to do some more clever work in software to measure the speed of change and basically predict where the results will settle. This should give a fast reading despite the pH probe actually taking ages to settle. And also, let’s face it, getting pH accurate to one decimal place is great for most situations, and the extra place may be questionable anyway as I’m not sure the accuracy is quite equal to the resolution.

And finally, the battery is from Adafruit, as detailed in the overview page. With a sleep current of 7μA against a capacity of 1200mAh, we should be good for a couple of years I reckon, even if we spend a fair fraction of one percent of the time awake.

The microcontroller sketches that configure and then run the sensor are available over at github – we are developing a system based on Node-RED to receive the data that you can also download from github. I hope that you find our work useful, and build something yourself with it, just as we’ve built on the astounding work of so many others. Happy hacking!!

The post Wireless pH sensor appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2014/05/wireless-ph-sensor/feed/ 7
Node-red web page – an example to get you started https://l0l.org.uk.archived.website/2014/01/simple-node-red-web-page/ https://l0l.org.uk.archived.website/2014/01/simple-node-red-web-page/#comments Sat, 11 Jan 2014 19:16:33 +0000 https://l0l.org.uk.archived.website/?p=275 NB: I no longer think this is a good way to do this! It was a first go, and there is a lot wrong with it.  I intend to revisit the web-page idea at some point, and will post something better then. Now we use Freeboard to display data – there is a freenode node […]

The post Node-red web page – an example to get you started appeared first on layer zero labs.

]]>
NB: I no longer think this is a good way to do this! It was a first go, and there is a lot wrong with it.  I intend to revisit the web-page idea at some point, and will post something better then.

Now we use Freeboard to display data – there is a freenode node for node-red in the contrib section – it makes it super easy to setup and configure. See http://incredibleaquagdn.no-ip.info/?load=dashboard.json for an example of how it looks.

A simple node-red web page

In the aquaponics installation we’re working on, node-red is running on a raspberry pi controlling an aquaponics system. It receives mqtt messages every second containing the readings from various sensors.

I wanted to create a simple web page that displays the data from each sensor, updating every 2 seconds.

I’m quite new to the Internet of Things and to event-driven programming in general, so if you are already an expert you will probably think my solution is hacky for all the wrong reasons. If so feel free to comment … constructively 🙂 For example, I suspect a “proper” node-red web page solution might involve node-red pushing data to the page in real time, but I’m going to keep it simple here and let it poll for its data.

Components:

1. A web page (HTML and Javascript) that sends an HTTP request to node-red every 2 seconds  and displays the data returned

2. A node-red object that knows the latest values of all the sensors

3. An httpRequest node configured to accept the page’s requests, triggering a flow that grabs the sensor values and returns them to the page via a httpResponse.

Http request and response in node-red

I jumped in with the node-red bit first, being the most fun. To simulate the messages containing sensor data I mocked up some streams of data using injectors.

node-red web page stage 1

Data buffer

The data buffer keeps hold of the latest sensor data, passing it through to the http response when a request comes in. It works like this: when a message arrives on a sensor data topic, it updates its array of sensor values, and exits. But when it receives a message via the http request node, it adds the latest data into the message object.

context.data = context.data || new Object();
switch (msg.topic) {
    case "concavity":
        context.data.concavity = msg.payload;
        msg = null;
        break;
    case "altitude":
        context.data.altitude = msg.payload;
        msg = null;
        break;
    default:
        msg.data = context.data;
}
return msg;

 

Page template

This is the html for the full page.

Hello there 
Altitude: {{data.altitude}}
Concavity: {{data.concavity}}
Other configuration

The http request node is configured for the url /boo and the GET method. The http response node needs no configuration.

Full flow
[{"id":"66f381b0.990c8","type":"http response","name":"http out","x":657,"y":233,"z":"ad00793e.52ff88","wires":[]},{"id":"ec3dfdc9.13c2","type":"http in","name":"http in","url":"/boo","method":"get","x":129,"y":329,"z":"ad00793e.52ff88","wires":[["ab90d0fa.546f3"]]},{"id":"cad43099.352bd","type":"template","name":"Page Template","template":"Hello there <br />\n\nAltitude: {{data.altitude}}<br />\nConcavity: {{data.concavity}}","x":485,"y":232,"z":"ad00793e.52ff88","wires":[["66f381b0.990c8"]]},{"id":"1c8929d0.e376d6","type":"inject","name":"","topic":"altitude","payload":"3","repeat":"3","crontab":"","once":false,"x":140,"y":216,"z":"ad00793e.52ff88","wires":[["ab90d0fa.546f3"]]},{"id":"315341ba.ceacbe","type":"inject","name":"","topic":"concavity","payload":"65","repeat":"2","crontab":"","once":false,"x":138,"y":271,"z":"ad00793e.52ff88","wires":[["ab90d0fa.546f3"]]},{"id":"ab90d0fa.546f3","type":"function","name":"Data buffer","func":"context.data = context.data || new Object();\nswitch (msg.topic) {\n    case \"concavity\":\n        context.data.concavity = msg.payload;\n        msg = null;\n        break;\n    case \"altitude\":\n        context.data.altitude = msg.payload;\n        msg = null;\n        break;\n    default:\n    \tmsg.data = context.data;\n}\nreturn msg;","outputs":1,"x":319,"y":230,"z":"ad00793e.52ff88","wires":[["cad43099.352bd"]]},{"id":"261b1fb8.d9e4e","type":"inject","name":"","topic":"altitude","payload":"2","repeat":"2","crontab":"","once":false,"x":143,"y":169,"z":"ad00793e.52ff88","wires":[["ab90d0fa.546f3"]]}]

If you deploy this and point your browser to localhost:1880/boo then you should see the (very simple) page. It won’t update automatically, but if you keep refreshing you should see the altitude changing from 2 to 3.

Node-red really is awesome. It’s amazing how quickly you can get something up and running, end to end. This delightfully bare-bones way of getting started was inspired by this node-red web page suggestion by knolleary here

Auto-update using Javascript

Well I thought I was starting with the node-red bit and would have to go on to web servers and static templates and so on later. But in the course of looking for a simple way to add the auto-update functionality, I ended up with a totally node-red web page – everything about it is programmed in node-red.node-red web page auto-update

There are two urls serving http requests – /web and /data. When you go to /web it serves up a simple page with a placeholder div and a js script. The script sets a function to run every 2 seconds. The function sends a request to /data and replaces the text in the div with the response, i.e. the latest sensor data (here mocked out by injectors publishing timestamps).

Auto Update Script

The auto update script node is also just a template but it contains the script that will kick off the auto-updating. The URL is hard-coded.

<script>
    setInterval(function(){	
	    var theUrl = "http://localhost:1880/data";
	    var xmlHttp = new XMLHttpRequest();
	    xmlHttp.open( "GET", theUrl, false );
	    xmlHttp.send( null );
	    document. getElementById('data')
	    	.innerHTML = xmlHttp.responseText;
    },2000);
</script>
<div id="data">... Loading ...</div>

The result is that if you go to localhost:1880/web it should say “Loading …” for a few seconds and then start to display the data, updating every 2 seconds as required.

Future Improvements

Clearly this is just a proof of concept. Where to go next?

  • Appearance. Present the data in a nice format on the page.
  • Improve the code. The hard-coded url is yucky and the html markup is … minimal. Also something doesn’t feel right about having the js script as text in the template node, but maybe it’s fine.
  • Add the ability to send requests in the other direction, from the web page and have node-red act on them.
  • Add a download option for historical data
  • etc.

Comments welcome

Have a nice day

The post Node-red web page – an example to get you started appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2014/01/simple-node-red-web-page/feed/ 17
Command line control of arduino using ino https://l0l.org.uk.archived.website/2013/11/command-line-control-arduino-using-ino/ https://l0l.org.uk.archived.website/2013/11/command-line-control-arduino-using-ino/#respond Tue, 19 Nov 2013 13:07:50 +0000 https://l0l.org.uk.archived.website/?p=202 As we’re going to be programming the arduino via the raspberry pi over ssh, we need a command line tool to talk to the arduino. Luckilly several such ways exist, including make-files from several sources. I chose to use a tool called ino which seems to have packaged up the toolchain in a fairly decent […]

The post Command line control of arduino using ino appeared first on layer zero labs.

]]>
As we’re going to be programming the arduino via the raspberry pi over ssh, we need a command line tool to talk to the arduino. Luckilly several such ways exist, including make-files from several sources. I chose to use a tool called ino which seems to have packaged up the toolchain in a fairly decent way.

I’ve just used this to connect to the pi in Todmorden and remotely upload a fresh copy of the firmware and reset the arduino! now it’s started talking mqtt again, and all from across the internet!

Installation was relatively straightforward – good guide here: http://www.recantha.co.uk/blog/?p=1103.

sudo aptitude update && sudo aptitude upgrade -y
sudo aptitude install arduino picocom python-pip
sudo easy_install configobj jinja2 ino

Then create a new directory for a sketch, enter it and initialise ino:
mkdir AquaSensors
cd AquaSensors
ino init

Then the source files can be copied across into the src directory, external libraries into the lib directory (still inside a directory for each library tho!) – then compile with:
ino build

If we want to copy a hex file rather than compile it locally, then it should be renamed as .build/boardname/firmware.hex so in our case .build/mega2560/firmware.hex

Either way, to take the hex file and to upload it:
ino upload
from within the sketch directory.

To set sketch based or global defaults for ino, such as serial port & speed or board type, you can create an ini file.

This can be put either in the sketch folder as ino.ini, or as /etc/ino.ini or as ~/.inorc. The latter option gives a default for the user, the /etc/ino.ini one is global across the system (all can be overridden by command line options at invocation.)

Our file is global across all users so the following was saved to /etc/ino.ini:

board-model = mega2560

The post Command line control of arduino using ino appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2013/11/command-line-control-arduino-using-ino/feed/ 0
raspberry pi running node-red, wiring-pi to pwm control a light https://l0l.org.uk.archived.website/2013/09/raspberry-pi-running-node-red-wiring-pi-to-pwm-control-a-light/ https://l0l.org.uk.archived.website/2013/09/raspberry-pi-running-node-red-wiring-pi-to-pwm-control-a-light/#respond Fri, 20 Sep 2013 13:27:11 +0000 https://l0l.org.uk/?p=57 OK so putting node-RED on the raspberry pi was almost as easy as getting it onto my computer – see previous post here. I started with the occidentalis distro from adafruit – and to install node.js itself I needed to use different package to match the pi wget http://node-arm.herokuapp.com/node_latest_armhf.deb sudo dpkg -i node_latest_armhf.deb but apart […]

The post raspberry pi running node-red, wiring-pi to pwm control a light appeared first on layer zero labs.

]]>
OK so putting node-RED on the raspberry pi was almost as easy as getting it onto my computer – see previous post here.

I started with the occidentalis distro from adafruit – and to install node.js itself I needed to use different package to match the pi

wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb

but apart from that things were fairly smooth, I farted around for ages trying to get a manual build of wiring-pi to be recognised, then just randomly tried a

npm install wiring-pi

to install the library directly, and that worked great!  I edited the node-RED settings.js file to add in the ability to use wiring-pi in the global context, and then restarted node-RED.

I wanted both mosquitto and node-RED to start automatically on boot, and rather than use rc.local I created a file in /etc/init.d like so:

sudo nano /etc/init.d/mqttstart
sudo chmod 755 /etc/init.d/mqttstart
sudo update-rc.d mqttstart defaults

the mqttstart script just consists of:

mosquitto -d
cd /home/pi/node-red
screen -dmS red sudo node red.js

So after all that setup; I loaded up node-RED and copied in the blink example and got that working!! but then changed the code around a bit, and looked into the pwm capabilities of the pi. Turns out it has one built-in pwm function and the wiring pi library provides soft-pwm on other pins.

So I changed the pin to pin 1 (wiring-pi convention) and hacked at the blink example function code to show the pwm functioning:

node-RED code for pwm light
node-RED code for pwm light

Here is my code, as per the example on the node-RED documentation, just copy the text into the clipboard, then select import from clipboard in the top right and paste it in:

[{"id":"ce4d5b27.31b2a8","type":"function","name":"fade LED up and down on input","func":"\n// select wpi pin 1 = pin 12 on header\nvar pin = 1;\n\n// initialise the wpi to use the global context\nvar wpi = context.global.wpi;\n\n// use the default WiringPi pin number scheme...\nwpi.setup();\n\n// set the mode to pwm output\nwpi.pinMode(pin, wpi.modes.PWM_OUTPUT);\n\n// do the fade up/down in brightness thing\n\nfor (var i=0; i<256; i++){\nwpi.pwmWrite(pin, i*4);\npausecomp(5);\n}\nfor (var i=256; i>-1; i--){\nwpi.pwmWrite(pin, i*4);\npausecomp(5);\n}\n// we don't \"need\" to return anything here but may help for debug\nreturn msg;\n\n// timing function hack kudos Pavel Bakhilau via Sean McManus\nfunction pausecomp(ms) {\nms += new Date().getTime();\nwhile (new Date() < ms){}\n} ","outputs":1,"x":505,"y":370,"wires":[["6c906a60.936f94"]]},{"id":"df3260b7.20cda","type":"inject","name":"tick","topic":"","payload":"","repeat":"1","crontab":"","once":false,"x":291,"y":344,"wires":[["ce4d5b27.31b2a8"]]},{"id":"6c906a60.936f94","type":"debug","name":"","active":true,"x":730,"y":385,"wires":[]}]

And now it works to light an led progressively.

Then I replaced the directly driven led with one driven by a TIP120 transistor – keeping a resistor (820Ω) in place to limit the current out of the pi. I haven’t got a convenient 12V load to test it with right now but here’s the same led but with a lot more current drive potential!

TIP120 driving an LED from the pwm pin of raspberry pi
TIP120 driving an LED from the pwm pin of raspberry pi

As a nice way to check my sanity, I set the light onto 100% and measured the current drawn from the pi – my cheap multimeter measured 2.31mA which is gratifying as my calculations here predicted 2.3mA! Way to go theoretical predictions!

The post raspberry pi running node-red, wiring-pi to pwm control a light appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2013/09/raspberry-pi-running-node-red-wiring-pi-to-pwm-control-a-light/feed/ 0
Tweeting with Node-RED via a mqtt broker https://l0l.org.uk.archived.website/2013/09/tweeting-with-node-red-via-a-mqtt-broker/ https://l0l.org.uk.archived.website/2013/09/tweeting-with-node-red-via-a-mqtt-broker/#respond Mon, 16 Sep 2013 13:26:58 +0000 https://l0l.org.uk/?p=50 Having had a wonderful weekend at Wuthering Bytes, I decided to try and install the fabulous Node:RED tool and try to use it with mqtt to tweet the light level. Firstly Node-RED depends on node.js, so I installed node.js via Chris Lea’s ppa – he seems like the right sort of person to package up […]

The post Tweeting with Node-RED via a mqtt broker appeared first on layer zero labs.

]]>
Having had a wonderful weekend at Wuthering Bytes, I decided to try and install the fabulous Node:RED tool and try to use it with mqtt to tweet the light level.

Firstly Node-RED depends on node.js, so I installed node.js via Chris Lea’s ppa – he seems like the right sort of person to package up the current stable version and keep it up to date. The instructions here: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#ubuntu-mint worked fine except that I omitted the specific version string and apt-get automatically chose the more recent version. I got v0.10.18-1chl1~raring1 which is bang up to date. If I’d used the package manager without adding Chris’s repository then I would have got v0.6.19~dfsg1-5ubuntu1 which is almost certainly too old for node-RED.

Then to install Node-RED itself – the installation page here: http://nodered.org/docs/getting-started/installation.html is very well written so I won’t duplicate it here. Helpfully, the example of installing additional nodes is for twitter, so I went ahead and did a

 npm install ntwitter oauth

then I could just get going with

node red.js

and voila! my browser at localhost:1880 now displays a Node-RED screen.

Next up – install a mqtt broker – seems like mosquitto is a good one, but again the official repositories lag way behind the code, the ubuntu one is at 0.15 and the mosquitto provided one (http://mosquitto.org/download/) is at 1.2! I started it with a

mosquitto -d

and my test node:RED program is this one:

node-RED1

It’s super easy to configure the mqtt subscribers and publishers, I used an injection node as a trigger and firstly saw that messages were flowing into mqtt and out to the debug module. Then I rewired it, clicked deploy, and then my tweet was sent straightaway! (the injector fires at startup by default).

 

 

The post Tweeting with Node-RED via a mqtt broker appeared first on layer zero labs.

]]>
https://l0l.org.uk.archived.website/2013/09/tweeting-with-node-red-via-a-mqtt-broker/feed/ 0