# Streetlight Control System Based on Wireless Communication over DALI Protocol
## 4 Implementation of the Wireless Node
### Software Node  
As mentioned in Section 4.1, we used a processing and radio module: the SOC 2530 by Texas Instruments. To develop wireless applications with this circuit, Texas Instruments provides the IEEE 802.15.4 medium access control (MAC) software stack TIMAC [43] for free. ZigBee was built on top of this standard. TIMAC consists of three components: MAC (IEEE 802.15.4 Medium Access Control Software Stack), HAL (Hardware Abstraction Library) and OSAL (Operating System Abstraction Library) [43; 44; 45]. IAR Embedded Workbench EW8051 [46] was used as the development environment. We created an application and a network layer on the medium access control layer for the wireless nodes. The application network is responsible for analyzing the received frames and for acting on the lamps and the rest of the node's peripherals. The network layer is responsible for the network creation operations and for appropriately routing the packets. Each packet that arrives at the node is processed to check whether the node is its final destination. Otherwise, it is routed towards another node. The node reacts depending on whether the received message is a DALI message (taking into consideration the kind of DALI message received) or a network message, according to the flowchart shown in Figure 15.  
The RF module only supports point-to-point and star (point-to-multipoint) communications. In a street lighting system, it is essential that the PAN coordinator can reach any node. This requirement makes the star topology completely useless, so we were required to modify the network layer somewhat to ensure a tree topology. The nodes have several tables containing the routing information of the messages. When the network is created, each node also creates a table where the nodeID is related to its MAC address or to the MAC address of the node to which the messages destined for the nodeID need to be routed. The coordinator's table contains the MAC address of the node and every router in the way of the node. The table size is predefined by the total length (maximum depth) of the network. Another field of this table is the child number that the node represents for its father. The table stored in any node  
Figure 15: Microcontroller program flowchart. only contains the MAC addresses of its children, in an order given by the coordinator. This way of creating the network allows the coordinator to use source routing packet transmission, in which the coordinator puts in the packet the addresses of the nodes through which the message must pass. From the individual node point of view, there are only two kinds of DALI frames, according to whether they require a response or not. For instance, for an arc power control command, just a frame is transmitted without any response from the ballast. In contrast, a backward frame is received for a ballast status query command. The microcontroller also manages the conversion to/from the Differential Manchester code. The microcontrollers do not usually have an integrated peripheral that communicates using Manchester coding, nor does this peripheral implement the DALI protocol. We needed to create this component using software and by creating a set of functions for the user to use to communicate with this virtual peripheral. The software component for DALI communication is relatively complex, as it must await responses from the DALI slave, consumes three timers of the microcontroller and is implemented on a physical level with input/output port pins. The coordinator node communicates directly with the industrial computer through USB and does not control any lamp. Because of this, we used the CC2531 module by Texas Instruments, shown in Figure 16[47]. In any case, any other module identified by the computer as a UART (universal asynchronous receiver-transmitter) can also be used. Lastly, we took into account the fact that the wireless modules installed in the street lamps are within anyone's reach.