• Dandroid@dandroid.app
    link
    fedilink
    arrow-up
    63
    ·
    10 months ago

    I was the lead engineer on an Openwrt router for 2 years at my old job. Their documentation is complete and utter shit, but their design is extremely intuitive. Whenever I said to myself, “hell, let’s just try this and see if it works,” it had an insanely high success rate.

    I didn’t know Lua going into this project, but when I left the company, it made me really wonder why more people don’t use Lua. It’s a really nice language.

    I really enjoyed having my own open source router that I could just drop new features into by adding packages and recompiling. I was sad when I had to send all my dev units back.

    • sugar_in_your_tea
      link
      fedilink
      arrow-up
      10
      ·
      10 months ago

      Yeah, Lua is really nice. It’s also fast and small. In fact, “Programming in Lua” is imo one of the best programming language books available, up there with Kernighan and Richie’s “The C Programming Language.”

      • Dandroid@dandroid.app
        link
        fedilink
        arrow-up
        4
        ·
        10 months ago

        Yes, I was shocked at how small it is. I had no experience working with such limited resources going into this project. Our router had 32MB of storage. At one point I was looked into adding a python interpreter, and it was like 11MB. The Lua interpreter is like 250KB. Tiny!

        Also, the ternary operator has the best syntax of any language I have ever used.

        x = [condition] and [true value] or [false value]

        No question marks or colons or anything weird. It’s a logical extension of && and || after commands in bash using keywords since it is a verbose language. I wish every language had this syntax.

        For contrast, python is:

        x = [true value] if [condition] else [false value]

        It just seems weird to me to have the condition in the middle.

        • sugar_in_your_tea
          link
          fedilink
          arrow-up
          3
          ·
          edit-2
          10 months ago

          Yeah, I’ve always hated Python’s ternary, and I use it every day at work. Though you can do the same in Python if you want:

          x = [condition] and [true value] or [false value]
          

          I consider that bad style because the dedicated syntax is preferred. You can also do similar in JS:

          x = [condition] && [true value] || [false value]
          

          The caveat in both (and Lua) is that you’ll get the false value if the true value is falsey.

          My favorite syntax is Rust:

          x = if [condition] { [true value] } else { [false value] };
          

          This preserves the flow you get with the ? :, allows [true value] to be falsey, and is idiomatic without having a lot of extra syntax.

          My favorite thing about Lua is that tables separate numeric from string keys, so you can do this:

          x = { metadata = ... }
          x[1] = 3
          x[2] = 4
          print(#x) -- prints 2
          

          This is really nice for representing something like an XML/HTML DOM, where numeric indices are child nodes, and string keys are attributes. Or you can store metadata about a list in the list itself (e.g. have a reference to the max value, min value, etc). It’s just really nice to work with.

      • banneryear1868@lemmy.world
        link
        fedilink
        arrow-up
        3
        ·
        10 months ago

        Lua is so friendly, I’ve run in to it in a few instances in different contexts. Currently have a “sound computer” shield for rpi that uses Lua to run community scripts, which turn the thing in to anything from synths to sequencers to loopers and some really esoteric stuff. Lua is so intuitive I’m able to tweak stuff and even add functionality to existing scripts without much effort.

    • j4k3@lemmy.world
      link
      fedilink
      English
      arrow-up
      7
      ·
      10 months ago

      I’m curious what you’re really referring to with Lua. (casual hobbyist here) Is that the UCI implementation stuff? I tried to use my intermediate Linux desktop user experience with bash in OpenWRT, but geez that is frustrating without all the bash extras I’m accustomed/detailed help/manual pages. That on top of trying to figure out NFTables is still a bit too much for my little brain to compress. I just started messing with UCI commands so I haven’t looked under the hood on that one.

      Any ideal device recommendations for fun chipsets to seek out and play with for embedded stuff in this space?

      • Dandroid@dandroid.app
        link
        fedilink
        arrow-up
        5
        ·
        edit-2
        10 months ago

        The web UI backend stuff is all done in Lua. So receiving and processing forms was all Lua. My main feature that I implemented was a REST API that was called from another product that my company sold. So I had to do all the REST API processing and data validation and whatnot in Lua.

        I don’t really have recommendations, because I really only knew our product. If I knew what I get, I probably would have got that instead of the Asus router that I ended up with when I had to return my work materials.

    • tslnox@reddthat.com
      link
      fedilink
      arrow-up
      2
      ·
      10 months ago

      I pretty successfuly ran a combo of TP-Link with OpenWRT connected with cable to a cheap dumb Edimax, which in turn was connected through wifi to downstairs Zyxel ADSL router from O2 ISP.

      Essentially the Edimax bridged the internet (there was only one place where the signal was strong enough) from downstairs, sent it to the TP-Link and that one spread wifi on the upstairs floor (so we could use phones/notebook) and my brother’s and mine desktop PCs were connected to it by cable. A bit of an overcomplicating simple problem, but it worked (otherwise we would either have no wifi or would have to buy a different router with 2 separate WiFi chips).

      • Dandroid@dandroid.app
        link
        fedilink
        arrow-up
        3
        ·
        10 months ago

        OpenVPN server was my number 1. Being able to VPN back into my home from anywhere in the world was amazing. I can’t really remember any other, since it was more than a few years ago.

          • WaterWaiver@aussie.zone
            link
            fedilink
            English
            arrow-up
            3
            ·
            edit-2
            10 months ago

            Not quite the same thing, you can’t do layer 2 VPNs on wireguard (I ended up using tinc for that on a previous project, it worked well). For layer 3 however it’s really good. Fast, simple, reliable, client works well on the platforms I’ve tried so far.

              • WaterWaiver@aussie.zone
                link
                fedilink
                English
                arrow-up
                2
                ·
                edit-2
                10 months ago

                My case for it was dealing with proprietary sensor devices with ethernet ports and garbage firmware. They could work if your server was on a different subnet, but a bunch of stuff broke (including the config tool) if you were not on the same ethernet LAN. The L2 tinc VPN allowed us to fix things without needing to walk around to the dozens of devices in a building with an ethernet cable, laptop and a ladder.

                The firmware (& vendors) of the devices that we spent over 100K on were garbage in so many ways. One product’s proprietary server software would misbehave (read: open files but never close them, after a time running out of file descriptors) which would then cause its fleet of individual sensors to all start SYN flooding it. Another brand’s device model required us to spend lots of time manually updating them through every version of firmware because you were not allowed to jump straight to the latest version. I think it took an hour to complete the process for each unit (during which they’d get really hot and presumably throttle).

                A bonus of tunnelling things back to our server over tinc was that everything was now encrypted. I used cheap GL.inet “mango” routers running OpenWRT to backhaul the sensors over the existing shared wifi network (rather than needing dedicated copper or wired VLANs). They worked almost like magic – a weird wifi stack reliability issue required me to write a watchdog that rebooted them, however, otherwise we were back on ladders every few days :| But once that pain was over things overall worked much better.

                Aside: Don’t buy ANY off-the-shelf sensor product without first:

                1. Confirming that you’re not tied to their proprietary server software. Them claiming that they speak an open protocol is NOT enough.
                2. Buying a few to actually test the above AND reliability over the span of at least a week’s operation AND that they’re not just outright lying about the device’s accuracy/reliability/usefulness/etc

                I made the mistake of being on holidays when the decisions on what to buy were made :P I ended up designing and building some of our sensor devices (somehow at a cheaper price even including my labour) that worked better for us, but shortly afterwards the funding ran out and I got a job elsewhere.