Creating an installable lua only Hello World Package for OpenWrt
Introduction
In a previous post (Adding new elements to OpenWrt's LuCI on GL-MiFi) we saw how to add new entries to the web interface of a device running OpenWrt by adding/editing files directly on the device itself. In this post we will see how to create an installable .ipkg package to do the same. We will be using the OpenWrt SDK on an Ubuntu host to build the .ipkg package.
I will be using Linksys's MR8300v1 WiFi router which runs on Qualcomm SoCs based on the ipq40xx platform (Quad core ARMv7)
Setup the development device (aka router)
- Provide internet to the development router by connecting a LAN cable from your home WiFi router's LAN port to development routers WAN port.
- Connect a straight LAN cable from your laptop to router’s LAN port
- Install OpenWrt from https://openwrt.org/toh/linksys/mr8300
- [Optional] Install again if you want to ensure that same version of OpenWrt is in both flash partitions
- Login to the device using web browser https://192.168.1.1/ (Login: root, leave password blank)
- Go to https://192.168.1.1/cgi-bin/luci/admin/system/admin and set a password for root, otherwise the router won’t be accessible via SSH
-
[Optional] In the next step, we will be installing development tools on a
Ubuntu host. If you - like me - are running Ubuntu inside a VM on Windows,
you will need to add network adapter to the VM in the bridged, bridging to
the physical Ethernet NIC of your laptop to which you have connected a LAN
cable to the development device (i.e. router running OpenWrt)
[Optional] Create bridge adapter for your Ubuntu running inside a VM so that your development router assigns an IP to your VM and you are able to access the router from the VM over SSH
-
Access your router over SSH:
root@192.168.1.1
Install luci-lua-runtime, while logged into the router over SSH:
- opkg update
- opkg install luci-lua-runtime
Setup SDK for OpenWrt on Ubuntu 24.04.1 x86_64 and build the Hello World App
- While in ~
- sudo apt update
- sudo apt upgrade
- sudo apt install -y build-essential git subversion libncurses-dev zlib1g-dev gawk flex gettext wget unzip python3 python3-setuptools rsync zstd tree
- Locate SDK URL on OpenWrt’s website
- Go to https://downloads.openwrt.org/releases/
- Click on 24.10.2 (Corresponds to OpenWrt installed on development device)
- Click on targets
- Click on ipq40xx (Development device’s platform)
- Click on generic
- Scroll down and under the section titled “Supplementary Files” locate link to file named something like: openwrt-sdk-24.10.2-ipq40xx-generic_gcc-13.3.0_musl_eabi.Linux-x86_64.tar.zst
- Copy link to that file and use it in the next step.
- wget https://downloads.openwrt.org/releases/24.10.2/targets/ipq40xx/generic/openwrt-sdk-24.10.2-ipq40xx-generic_gcc-13.3.0_musl_eabi.Linux-x86_64.tar.zst
- unzstd openwrt-sdk-24.10.2-ipq40xx-generic_gcc-13.3.0_musl_eabi.Linux-x86_64.tar.zst
- tar -xf openwrt-sdk-24.10.2-ipq40xx-generic_gcc-13.3.0_musl_eabi.Linux-x86_64.tar
- rm openwrt-sdk-24.10.2-ipq40xx-generic_gcc-13.3.0_musl_eabi.Linux-x86_64.tar
- cd openwrt-sdk-24.10.2-ipq40xx-generic_gcc-13.3.0_musl_eabi.Linux-x86_64
- mkdir -p package/luci-app-helloworld/luasrc/{controller,view}
- cd ~/openwrt-sdk-24.10.2-ipq40xx-generic_gcc-13.3.0_musl_eabi.Linux-x86_64/package/luci-app-helloworld
-
nano Makefile
1 2 3 4 5 6 7 8
include $(TOPDIR)/rules.mk LUCI_TITLE:=LuCI Hello World LUCI_PKGARCH:=all include $(TOPDIR)/feeds/luci/luci.mk $(eval $(call BuildPackage,luci-app-helloworld))
-
nano luasrc/controller/helloworld.lua
1 2 3 4 5 6 7 8 9
module("luci.controller.helloworld", package.seeall) function index() entry({"admin", "services", "helloworld"}, call("action_index"), _("Hello World"), 100) end function action_index() luci.template.render("helloworld") end
-
nano luasrc/view/helloworld.htm
1 2 3 4
<%+header%> <h2>Hello World App</h2> <button onclick="alert('Hello World!')">Click Me</button> <%+footer%>
- The layout should look like:
1 2 3 4 5 6 7 8 9 10
vboxuser@ubuntu-24:~/openwrt-sdk-24.10.2-ipq40xx-generic_gcc-13.3.0_musl_eabi.Linux-x86_64/package/luci-app-helloworld$ tree . ├── luasrc │ ├── controller │ │ └── helloworld.lua │ └── view │ └── helloworld.htm └── Makefile 4 directories, 3 files
- cd ~/openwrt-sdk-24.10.2-ipq40xx-generic_gcc-13.3.0_musl_eabi.Linux-x86_64
-
./scripts/feeds update -a
(Reference: https://openwrt.org/docs/guide-developer/toolchain/using_the_sdk)
(PS: I had to switch to Vi for internet because the command kept timing out in Airtel) - ./scripts/feeds install -a
- make menuconfig
- Go to LuCI → 3. Applications
- You will see 2 entries for luci-app-helloworld
-
Select first one and press the “Y” key, to turn the checkbox next to
luci-app-helloworld from
[M] to [*]
Enable the luci-app-helloworld from the Configuration - Highlight and press Save to save the .config
- Exit
-
make package/luci-app-helloworld/compile V=s
(Clean Command if needed: make package/luci-app-helloworld/clean) - scp -O bin/packages/arm_cortex-a7_neon-vfpv4/base/luci-app-helloworld_*.ipk root@192.168.1.1:/tmp
- ssh root@192.168.1.1
- opkg install /tmp/luci-app-helloworld_*.ipk
-
Open the router's web interface in your browser:
http://192.168.1.1/cgi-bin/luci/
annnd....
![]() |
This is what the entry in OpenWrt Device's Web UI would look like |
Comments
Post a Comment