Posts

node-red flow my tears the progammer said

 Having got a couple of weeks of node-red experience. I feel qualified to get a little critical. In my first post on node-red I did already find reason to complain about the lack of namespaces, there was a conflict in my project meaning I failed to access node-red-contrib-crypto-js-dynamic, my code instead called node-red-contrib-crypto-js and failed. My next target is the "flow". Flow is misnamed, there are flows of information through node-red, but what is called a "flow" is simply a named tab where you may put many different flows. If you choose to store information in a flow, you are storing information on the equivalent of a big piece of paper.  Once that piece of paper is full and you need a new one, then your new bit of paper/tab/flow will no longer have access to the information on your first bit of paper/flow/tab. Your only real resort is to use the global context. Both of these issues are a classic case of ease of use, hitting the threshold of big boys/gir...

A reliable tuya authentication in node-red

In passing when working with tuya and node-red I had a couple of issues, the first one was conflicts with node-red-contrib-crypto-js-dynamic and node-red-contrib-crypto-js. node-red just doesn't seem clever when it comes to duplicate node names. In this example I have replaced the "hmac" function with a copy called mj_hmac. This can be replaced with the hmac from node-red-contrib-crypto-js-dynamic or failing that you will be unable to pass the tuya secret key as a parameter and will have to enter it in the hmac node dialog. The second issue is that tuya authorisation is on a fixed timeout of two hours.  If you refresh the key at 1 hour and 59 minutes it will only be valid for 1 minute. This flow keeps track of the time remaining and refreshes just after expiry. I have not seen errors since. However as a backup plan I do have sub flows that if they see an error reauthenticate. If anyone is reading and interested I can post them as well. [ { "id" : ...

Node-red "easy" home automation

A few weeks ago, we had solar panels installed. Not before time given the energy price rises. The question naturally arose as this isn't as yet a battery storage system as to how to use the excess energy when there is any? An obvious answer is to whack on the immersion heater if there is sufficient spare. We are using the Solax Cloud system for monitoring our panels and this provides a very simple API to get all the information needed in one REST call. So next up was to call an electrician to put the immersion on a socket and get a suitably rated smart plug one that doesn't just switch but reports consumption for good measure. Like most smart plugs this is a "tuya" device and so also has an API. So how am I going to program this with any number of languages to choose from? I have a house full of smart gadgets, harmony remotes, hue lights, nest thermostats, alexa routines, but I have never felt the need to look for a programming solution before now as I have never had ...

Problems in Pivacy - Electric Cars

 Electric cars are coming, in fact they are already here. Not hybrids plugins or otherwise, but full blown electric. If you commute daily there is a decent chance that despite the price gauging your long term overall cost of ownership will be cheaper than an infernal combustion engine. They are simpler to build, have less components that need servicing, there's no oil to change and with regenerative braking the brake pads last a lot longer. Your exhaust pipe won't fall off either as they don't have one. The diehard ICE fans will point out range issues and charging infrastructure. But sod them on range, belching diesel fumes so they can tow a second home up and down the Country a couple of times a year is not an argument anyone can win. Charging infrastructure is more interesting and obviously at the moment the ICE dinosaurs have a point. It is inadequate in the UK, there is little provision for on street charging, there a multiple standards and anecdotally plenty of broken ...

A Trait worse than death

Going back many a year before C++ was in general circulation I had occasion to write a graphics library. It would need to be able to use a couple of different screen based APIs and also assorted pen plotters. To this end the individual drivers populated a virtual function table that would be called by the API layer. In effect a manual implementation of a C++ class system with "virtual" methods. The need for languages to have these sorts of mechanisms is clear. Of late languages have broken away from C++ classes. Golang has instead the idea of an interface, the definition of an interface specifies what functions (no variables) that interface has. At that point any struct that contains all those functions can call a function that wants the interface as a parameter. It's a great concept, very flexible, a struct might satisfy any number of different interfaces without the need for inheritance. Rust decides to change the game again and has traits which are like interfaces but ...

A Rust Iterator example

The idea of having an iterator type allowing you to navigate containers in a standard fashion has become common in many languages including Rust. Sadly I think the documentation makes a mess of it. I seem to come across two examples on which gives out Fibonacci  sequence numbers and is not really what I'd call an iterator, you can't reiterate it again and so it's plain confusing to post it as an example. The other I come across is a structure with a Vec in it and that just returns the iterator for the Vec which does not exactly help you in coding a real iterator. So let's start off with what an iterator essentially is an go from there. When we have a structure which we want to iterate an iterator has two pieces of information it needs, it needs a reference to the structure itself and it needs to know where we are in indexing that structure. We can't store that position index in the structure itself as if we had a nested loop or even multiple threads it could be over...

Getting Rusty

Over the years I have written in many programming languages and even written a few. They all have pros and cons, things where they are ahead of the game and sometimes places where I feel they are going backwards. Really folks writing languages, why leave out  the c preprocessor or an equivalent? It's enormously useful and powerful. The last few years have been mainly golang which I have been very impressed with. Concise, secure and many innovative features. Not giving it full marks out of ten as I took a big dislike to it's "linter" that imposes styles that are pointlessly strict and actually unsuitable for some projects. Golang uses a "garbage collection" system for memory which is both a blessing and a curse. It makes things safe and secure for sure, but it means you never know quite what's going on. Plunging back into C/C++ for these tutorials though has reminded me of just how dangerous c can be, the potential to access beyond the end of arrays and l...