Programming languag...
 

Subscribe now and choose from over 30 free gifts worth up to £49 - Plus get £25 to spend in our shop

[Closed] Programming language choice for a Raspberry Pi

23 Posts
16 Users
0 Reactions
137 Views
Posts: 7090
Full Member
Topic starter
 

OK, oh great STW, I need advice on choosing on a programming language.

It's for a DIY heating controller for a Raspberry Pi. Right now, I need to write a small websockets server so that I can control it from my phone.

Obviously I could just write something in Python, and be done in less time than it takes to write this STW post, but that would be waaaay to easy.

I've tried [url= https://nim-lang.org/ ]Nim[/url]. That's quite nice to start with, but the websockets support seems to be quite limited, and I'm too lazy to rewrite the core libraries enough to make it work.

I also looked at [url= http://golang.org ]go[/url]. And it's really designed for exactly this sort of problem. So that's an option, but I don't really know much about go.

There's also [url= https://www.rust-lang.org ]Rust[/url] but the borrow checker makes my head hurt.

So, what do STW recommend? What are the cool languages right now?

It needs to be compiled, as I don't have much CPU available.


 
Posted : 10/12/2017 9:42 pm
Posts: 401
Free Member
 

How about assembly?


 
Posted : 10/12/2017 10:42 pm
Posts: 349
Free Member
 

I like go. I have nothing more to add.


 
Posted : 10/12/2017 10:43 pm
Posts: 12079
Full Member
 

I like Java or Ruby. But Python is probably easier, assuming you're OK with something that ugly.


 
Posted : 10/12/2017 10:48 pm
Posts: 0
Free Member
 

C ? You want it compliled and efficient. Its the obvious choice I would think.


 
Posted : 11/12/2017 7:37 am
Posts: 0
Free Member
 

It needs to be compiled, as I don't have much CPU available.

You really do, you know. New raspberry pis are more powerful than most laptops from just a few years ago. Including the cut down ones.

Rachel


 
Posted : 11/12/2017 7:42 am
Posts: 14045
Free Member
 

A heating controller is pretty simple though... check temperature sensor/s every X mins, if temp is below set level then turn heat off, otherwise leave on.

I have a Pi controlling the [all electric] heating in our other house - was going to do a web page for altering the temperature but I very rarely change the temperature setting so the temps for different times of the day are in the code. Saved running a web server as well.


 
Posted : 11/12/2017 9:24 am
Posts: 4954
Free Member
 

What ever you are familiar with and has a web socket implementation, unless you want to write your own. It's not a complicated program so doesn't have any performance requirements etc.


 
Posted : 11/12/2017 9:31 am
Posts: 349
Free Member
 

How about Elixir? It's built on the Erlang vm and Erlang is pretty cool.


 
Posted : 11/12/2017 9:36 am
Posts: 4954
Free Member
 

It needs to be compiled, as I don't have much CPU available.

Lol! There is loads of power on pi. You are only turning heating on and off. If you where really constrained on power and were using a pi you can always go bare metal.

You can implement a web page on a 8 bit avr. http://tuxgraphics.org/electronics/200611/embedded-webserver.shtml


 
Posted : 11/12/2017 9:39 am
Posts: 0
Free Member
 

Node.js and whichever websockets implementation you fancy?

https://stackoverflow.com/questions/16392260/which-websocket-library-to-use-with-node-js


 
Posted : 11/12/2017 9:43 am
Posts: 13594
Free Member
 

Obviously I could just write something in Python, and be done in less time than it takes to write this STW post, but that would be waaaay to easy.

Bash would be the purist's choice...


 
Posted : 11/12/2017 10:28 am
Posts: 14045
Free Member
 

.... which is what I used with the bash script triggering python scripts for switching heaters on or off.

[I've been called all sorts of thing but never a purist - I'll take it as a good thing 🙂 ]


 
Posted : 11/12/2017 10:37 am
Posts: 4597
Free Member
 

As you say Python is the easy choice.

Go doesnt have libraries to control all the various interfaces, I think it can control the GPIO pins, but not the SPI or I2C interfaces.

When I had a play with a pi, I did all my stuff in C, because its what I used to know from 20 years ago, and there are libaries available for all the interfaces.

Of course - a real man would do it in assembler.


 
Posted : 11/12/2017 10:38 am
Posts: 7090
Full Member
Topic starter
 

Compiled is also just easier to deal with - I don't end up with a ton of random Python libraries that need to be kept up-to-date (I'm not using Raspbian, just a rootfs constructed from buildroot, so that I don't need to deal with the whole systemd nonsense).


 
Posted : 11/12/2017 11:38 am
Posts: 19
Free Member
 

Python if you have used it before but I'd use [url= https://nodered.org/ ]Node-Red[/url] and I do..

This is a Node-Red 'flow' controlling a fridge (via a relay)

[img] [/img]

Control and temperature reporting is via MQTT but you could also use it to create a UI, websocket and/or Rest interface


 
Posted : 11/12/2017 12:01 pm
Posts: 13594
Free Member
 

which is what I used with the bash script triggering python scripts for switching heaters on or off.

Calling a python script is just a cop out, should be 100% Bash for full marks...


 
Posted : 11/12/2017 12:09 pm
Posts: 621
Free Member
 

allthegear - Member
It needs to be compiled, as I don't have much CPU available.
You really do, you know. New raspberry pis are more powerful than most laptops from just a few years ago. Including the cut down ones.

Rachel

Is that the 3B?

Maybe somethings wrong with mine but its a lot slower than my old laptop which must be 2013/14 vintage with an i5-u chip.

Not that it makes any difference anyway, it's a great little device for messing about with.

I'm kinda half-arsedly writing an aquarium controller for my reef tank at the moment. It's python right now, but I might rewrite it in Go as I'm hearing good things.


 
Posted : 11/12/2017 12:44 pm
Posts: 0
Full Member
 

what would i do? oh, not bother! It's your central heating not the space shuttle, a simple timer and single t/stat is quite enough, not need to add a load of IoT cobblers to make it unnecessarily complex, un-reliable and vulnerable to attack imo.


 
Posted : 11/12/2017 12:54 pm
Posts: 0
Free Member
 

You could make a c/h controller using a £1 PIC/AVR, that has plenty of power for that! My preference (and my half written c/h controller) is C++, but then that's what I'm most familiar with. C++ for the bottom layer that is, not doing any websockets stuff as you don't need to, simply a basic webpage with simple javascript and PHP server side which interfaces to the C++ code (using a fifo to send commands).

It's not complete and working at the moment, but I used the same mix of tech to control the dragon I built earlier this year - just open the webpage on your phone.


 
Posted : 11/12/2017 1:31 pm
Posts: 7090
Full Member
Topic starter
 

what would i do? oh, not bother! It's your central heating not the space shuttle, a simple timer and single t/stat is quite enough, not need to add a load of IoT cobblers to make it unnecessarily complex, un-reliable and vulnerable to attack imo.

Sure, but where's the fun in that?


 
Posted : 11/12/2017 1:33 pm
Posts: 0
Full Member
 

oldnpastit
Sure, but where's the fun in that?

True, but where's the fun having to spend Christmas day in the Garden, in the freezing cold, watching your house burn to the ground because some Russian Hackers has taken control of your CH system and set it to explode!

(we all know from various films that common or garden household and Office systems can actually be remotely turned into explosive or deadly devices by Hackers..... 😉


 
Posted : 11/12/2017 8:45 pm
Posts: 0
Free Member
 

As above, NodeRed.


 
Posted : 11/12/2017 9:52 pm
Posts: 7090
Full Member
Topic starter
 

True, but where's the fun having to spend Christmas day in the Garden, in the freezing cold, watching your house burn to the ground because some Russian Hackers has taken control of your CH system and set it to explode!

I guess I'll have to write it in Rust then, and get my head round the borrow checker.

(Although I think the boiler has its own thermostat to prevent it overheating, but I could bypass it in order to encourage a bit more discipline in my coding).


 
Posted : 11/12/2017 9:53 pm