Home Contents | # TTN Networking | Rawio | Core4 Lua Event System

## DESCRIPTION

The TTN networking tunnels ethernet over RS485 at typically 115200bps using a token passing topology.

While slow by todays standards, this allows reuse of old wiring with modern protocols, as long as the protocols are carefully designed for low bandwidth use.

A TTN is set up by configuring a RS485 serial interface into TTN mode.

The controller can be set up to bridge between TTN and regular ethernet. Bridging works similar to and ethernet switch. Nodes are simply wired into the network and are automatically detected. DHCP, if required, works as expected.

### Example intialization code for station mode

The TTN interface will get its own IP address and netmask on the TTN network.

The Core4 kernel will be able to route between ethernet and TTN.

Routing mode has the advantage of completely isolating the TTN from any broadcasts on the ethernet segment.
Routing mode has the disadvantage that you will now have to explain to a field tech how to set up routing.

Returns a handle to the serial port. The handle must be kept open at all times. When closing the handle, the TTN network interface shuts down.

Keep the handle in a global lua variable to prevent lua's garbage collection from throwing it away. There is no data transfer access to the serial port handle via read()/write() from the application.

When closing the handle, the network interface is not deleted, because the kernel cannot delete a network interface. When reopening the device, any existing interface is reused.

function ttn_install_interface(name, ip, mask) local ttn = rawio.open("/dev/" .. name) if (ttn) then -- This registers a new network interface with the same name as the serial port, e.g.: "ttyS7" -- The interface is registered, but still disabled. ttn:setupComm{ speed=115200, ldisc="ttn" } -- Make sure bridging is disabled. -- This is just for safety just in case some previous code did run a bridge here. ttn:ttnBridgeTo(nil) -- Assign the IP and turn it on rawio.ifconfig(name, { up=false }) if (ip and mask) then rawio.ifconfig(name, { dynamic=false, ip=ip, netmask=mask }) -- Static mode else rawio.ifconfig(name, { dynamic=true, ip="0.0.0.0", netmask="0.0.0.0" }) -- DHCP mode endif rawio.ifconfig(name, { up=true }) end return ttn end -- Install with DHCP ttn = ttn_install_interface("ttyS7") -- Install with fixed IP ttn = ttn_install_interface("ttyS7", "192.168.1.123", "255.255.255.0")

### Example intialization code for bridging mode

With bridging, all devices on the TTN will be visible in the ethernet network. This is supposed to work similar to a regular ethernet switch.

To keep the bandwidth usage in check, the bridging software will block almost all broadcasts from going into the TTN that are not absolutely necessary to make it work. This means only ARP, DHCP and Teratronik DISCOVER may pass.

Returns a handle to the serial port. The handle must be kept open at all times. When closing the handle, the TTN network interface shuts down.

Keep the handle in a global lua variable to prevent lua's garbage collection from throwing it away. There is no data transfer access to the serial port handle via read()/write() from the application.

When closing the handle, the network interface is not deleted, because the kernel cannot delete a network interface. When reopening the device, any existing interface is reused.

function ttn_install_bridge(name) ttn = rawio.open("/dev/" .. name) if (ttn) then -- This registers a new network interface with the same name as the serial port, e.g.: "ttyS7" -- The interface is registered, but still disabled. ttn:setupComm{ speed=115200, ldisc="ttn" } -- The TTN bridge is installed as a filter between the operating system and the ethernet interface "eth0" -- The operating system continues to see eth0 as it's regular network connection. -- The system's IP address is still assigned to eth0. -- The TTN interface does not get an IP address assigned. ttn:ttnBridgeTo("eth0") -- Make sure it has no IP configured and turn it on rawio.ifconfig(name, { up=false }) rawio.ifconfig(name, { dynamic=false, ip="0.0.0.0", netmask="0.0.0.0" }) rawio.ifconfig(name, { up=true }) end return ttn end ttn = ttn_install_bridge("ttyS7")