top | item 40262115

Cylon: JavaScript framework for robotics, drones, and the Internet of Things

90 points| nateb2022 | 1 year ago |github.com | reply

51 comments

order
[+] lelanthran|1 year ago|reply
I write embedded stuff for many of the popular IoT chips/modules/devkits/boards.

So, yes, there's a lot of high-level GC'ed languages that "run" on these systems.

For hobbyist one-off projects (where you can overspec the hardware by 10x without any negative financial impact to the project) they are great. For mass-production of a device, the extra RAM (and resources in general) that they require tend to be double what you would ordinarily need if written in C (or a crippled dialect of C++).[1]

For the best high-level logic control of embedded devices, you cannot beat esphome, and that's because that project converts the high-level logic (specified in YAML) to native C and/or C++ code, which is then pushed OTA to the device. That approach keeps the firmware as lean as possible.

[1] My best experience with stuffing a more abstract language into something like an atmega328 (I believe that's what's used for Arduino) is with a special purpose-built compiler that compiled a PLC type language of my own design (only for controlling and switching digital IO and reading ADC) to a byte code, which was run by a tiny interpreter on the atmega, using three bytes per instruction+operand.

Such a scheme allowed tons of conditional logic to be stuffed into the flash area, as the 'interpreter' on the chip would read and execute 3 bytes at a time from flash. The native-code version of the same conditional logic could easily be 10x the size.

[+] oneplane|1 year ago|reply
In interested in learning why say, a device would be much more expensive if we use 1GiB of DRAM chips instead of 32MB. The chips themselves have the same physical footprint, power requirements, and as long as you pick one that is compatible with your µC or SoC you don't need to change that either. That leaves the cost of the chip, where you might need to spend a few cents more. I'm pretty sure the consumer doesn't care if the widget costs $21.55 or $21.59. The same would apply to NAND flash storage.

I do get that if you have to produce millions of widgets that a few cents here and there might add up, but if you just exchange one part for a physically similar but higher capacity part, and the list price difference is really small, why would that be such a hurdle? I'm not talking about redesigning all the power supplies, adding a PMIC or building an entire computer, but even in the WRT54G days you could just solder replacement DRAM and NOR chips and be done for a few cents for a 500% increase in capacity. In later models you could still do that but the NOR became NAND and BGAs are harder, but it's still pretty easy and cost-effective.

In the EE world, designing for manufacture does try to squeeze every fraction of a cent out of everything, while in the software world using 10MB of RAM instead of 1MB is fine as long as you decode your PNGs correctly (via an earlier libpng reference implementation comment a few days ago). Even at volume, I doubt that saving a tenth of a cent really matters until you hit some extreme production numbers. (even 10 million units would at best save you $10k)

Mechanically there would be something to consider, i.e. connectors vs screws vs solder vs glue etc, those all have a direct impact on how reliable a connection is, how long it will last, and how easy it is to manufacture (and how easy it is to take apart later). But fractions of a cent when compared to all the other aspects?

[+] globalnode|1 year ago|reply
any chance you'd like to share your PLC to bytecode stuff? I've been thinking of doing something like this too, even for say scripting of game events, or like you did for controlling the logic of I/O's. but sadly theres never enough time.
[+] irrational|1 year ago|reply
What are the pros and cons of this compared to Johnny-Five?

http://johnny-five.io/

[+] jahewson|1 year ago|reply
This project looks to be long-dead, so the advantage would appear to be that johnny-five is alive.
[+] madcoderme|1 year ago|reply
Last commit was 8 years ago. I don't think anyone gonna use it now.
[+] lta|1 year ago|reply

[deleted]

[+] cess11|1 year ago|reply
I'd reach for Nerves.

https://nerves-project.org/

[+] lelanthran|1 year ago|reply
> I'd reach for Nerves.

Not applicable to the clear majority of IoT hardware; it's for embedded systems which are large enough to run Linux, basically.

From the website:

> Firmware sizes start in the 20-30 MB range.

[+] demondemidi|1 year ago|reply
Seems kind of pointless. A flight controller that can run JavaScript fast enough would be a waste of resources.
[+] _akhe|1 year ago|reply
JavaScript is a hell of a lot faster than Ruby, PHP, or Python, yet Python is mostly used for AI/ML. I think V8 is plenty "fast enough" (why wouldn't it be)?
[+] lelanthran|1 year ago|reply
> Seems kind of pointless. A flight controller that can run JavaScript fast enough would be a waste of resources.

According to the docs (for both this and the Johnny-Five project), the JS ONLY runs on a PC-class computer. You connect your IoT device to the computer that is running the JS program, and the JS program then controls the device. The IoT device must be tethered to a PC of some sort.

I'm guessing that controlling PC does things like "set GPIO-$X to input", "read GPIO-$X, "set GPIO-$Y to output", "write GPIO-$Y", "read ADC-$A", etc.

Maybe they designed their custom protocol to also handle time-constraints (like clocking a signal at a certain frequency on a particular pin), or maybe counting transitions on a digital input for specific duration, so that you can mostly do what you'd expect to, but I wouldn't bet on it.

My understanding of these types of projects is that they don't compile the input into a state-machine that is downloaded to the device; they send each instruction as and when it occurs.

This is especially problematic considering that the example in linked page is for a drone taking off, flying, then landing 10s later. You better hope that your drone doesn't ascend so fast in that 10s that it is out of range by the time the `land` command is issued.

[+] hpen|1 year ago|reply
Has anyone actually built embedded devices with JS? Sounds terrible
[+] imdsm|1 year ago|reply
Last commit: 8 years ago.
[+] charles_f|1 year ago|reply
Author appropriately named deadprogram
[+] hersko|1 year ago|reply
I don't think this is being maintained.
[+] cydodon|1 year ago|reply
...somewhat off topic... I seem to remember a JavaScript based system that could be installed on (old) mobile phones. This way one had easy access to all the phones sensors, wifi and could build simple GUIs to repurpose the phone. Does anyone know how it is called or where I can find something similar? Thanks =)
[+] Xeamek|1 year ago|reply

[deleted]

[+] omegabravo|1 year ago|reply
If you're pushing bits and bytes you might want tight control over the runtime and guaranteed execution time. If you're not, I think it's perfectly acceptable.
[+] portaouflop|1 year ago|reply
IMO if you work on IoT, you are in the wrong place. But who am I to judge.
[+] _akhe|1 year ago|reply
Naively said. Everything ends up in JavaScript.