From charlesreid1

Line 97: Line 97:
|Btn 0
|Btn 0
|Btn 1
|Btn 1
|Switch
|Switch State
|-
|-
|Pin 19
|(Pin 19)
|Pin 20
|(Pin 20)
|State
|
|-
|-
|0
|0

Revision as of 06:07, 17 March 2016

Linkz:

https://wiki.openwrt.org/doc/uci

http://mattventura.net/openwrt-stuff/

Overview

On the Widy, or any device running OpenWrt, the device's configuration is set using UCI, the Unified Configuration Interface. This is similar in spirit to the way that most routers have web interfaces that allow you to modify their configuration options. You can interact with the UCI system using two different UCI interfaces: one is the web interface, LUCI, and the other is the command line interface uci.

In each case, changes to the UCI options are written to a group of files located in /etc/config. The list of files looks like this:

# ls -l /etc/config
-rw-r--r--    1 root     root           724 Mar 16 22:33 dhcp
-rw-r--r--    1 root     root            62 Oct  1  2014 dropbear
-rw-r--r--    1 root     root          2024 Mar  3 06:25 firewall
-rw-r--r--    1 root     root           151 Oct  1  2014 fstab
-rw-r--r--    1 root     root           624 Oct  1  2014 luci
-rw-r--r--    1 root     root           449 Mar 16 22:31 network
-rw-r--r--    1 root     root           677 Oct  1  2014 system
-rw-r--r--    1 root     root             0 Oct  1  2014 ubootenv
-rw-r--r--    1 root     root           717 Sep 20  2014 ucitrack
-rw-------    1 root     root           635 Oct  1  2014 uhttpd
-rw-r--r--    1 root     root           374 Mar  3 12:08 wireless

Each config file covers one major aspect of the Widy's operation.

Wireless Configuration

The wireless configuration file looks like this:

System Configuration

Link: https://wiki.openwrt.org/doc/uci/system

Q: What happens when you change /etc/config/file? Does it stay persistent?

Q: When and how does UCI override changes with defaults?

Q: How can I link UCI with the 3 slider buttons?

Slider Button Configuration

The Widy comes equipped with a slider button, with 3 positions:

  • 3G/4G
  • WISP
  • AP

Before we can control these buttons, we need to know their names.

Start by making a script that will run whenever the buttons are activated:

$ mkdir -p /etc/hotplug.d/button

Now create the file /etc/hotplug.d/button/buttons and add a command to log some information about the button in the system log:

#!/bin/sh
logger the button was $BUTTON and the action was $ACTION

Now save the file and exit. This script will run whenever the buttons on the Widy are activated.

Slide the button from the 3G/4G position to the WISP position. If you are connected directly via ethernet, your connection should stay alive.

Now look at the system log:

$ logread

You'll see a notice about a button being pressed, and a button being released. The "pressed" button is the starting position of the button.

Sliding it from the 3G/4G position (top) to the WISP position (middle) shows:

Jan 1 00:01:15 OpenWrt user.notice root: The button was BTN_0 and the action was pressed
Jan 1 00:01:15 OpenWrt user.notice root: The button was BTN_1 and the action was released

Then sliding it from the WISP position (middle) back to the 3G/4G position (top) shows:

Jan 1 00:01:18 OpenWrt user.notice root: The button was BTN_1 and the action was pressed
Jan 1 00:01:18 OpenWrt user.notice root: The button was BTN_0 and the action was released

How The Switch Works

By observing the output in the syslog, I deduced that there are only TWO buttons to set the state of a THREE-position switch. This is done by means of a truth table: with both switches off, it represents the null state (the switch is always set to something). If BTN_0 is on and BTN_1 is off, it represents one state; if BTN_0 is off and BTN_1 is on, it represents another state; and if BTN_0 and BTN_1 are both on, it represents a third state.

Btn 0 Btn 1 Switch State
(Pin 19) (Pin 20)
0 1 3G/4G
1 0 WISP
1 1 AP