To effectively serve people, it helps if the city authorities know how many vehicles are going where and when, which road is more crowded. So the traffic problem can be solved by increasing the road width or optimizing the traffic routes. The proposed solution counts the number of vehicles passing on road. The vehicles are two wheeler and four wheeler. The system logs the data on cloud in order to analyse the number of vehicles per minute and also counts the total number of vehicle passed. The Smart Counters are used around the city streets. ThingsBoard platform is used to store the data on cloud. The data made available for whoever needs or wants it. The proposed project can be implemented as a subpart of smart city project. This enables clever solutions to urban problems. It will indirectly help to make cities better place to live.
For the construction and development of road the system has to go through various process such as area identification, data collection and survey reports, service level benchmark, travel demand forecast-model development, Landuse and Transport Strategy and Proposal, etc according to [2] the comprehensive mobility plan by Nagpur improvement trust(NIT). The data collection and survey step can be accomplish through the proposed solution.
System Components
The hardware comprises of Raspberry pi and Smart counter unit. Proposed system uses Cloud service from ThingsBoard open source IOT platform. Here we see detail information about the hardware and software part involved in the system.
1) Smart counter unit:
This unit counts the number of vehicle passing on the road. Hardware and system code make this unit smart i.e. capable of counting two wheeler and four wheeler vehicles separately per minute. This unit also counts the total number of vehicles. Unit uses separate two counters for two type of vehicles i.e. two wheeler and four wheeler. Prototype road is made in such a way that the smart counter unit can count vehicle counts individually.
2) Raspberry pi:
System is using raspberry pi 3 B+ model as a controller. Raspberry pi is used to perform operations and control the system flow.
Reference [6] the Raspberry Pi 3 Model B+ is the latest product in the Raspberry Pi 3 range.
¨ Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC @ 1.4GHz
¨ 1GB LPDDR2 SDRAM
¨ 2.4GHz and 5GHz IEEE 802.11.b/g/n/ac wireless LAN, Bluetooth 4.2, BLE
¨ Gigabit Ethernet over USB 2.0 (maximum throughput 300 Mbps)
¨ Extended 40-pin GPIO header
¨ Full-size HDMI
¨ 4 USB 2.0 ports
¨ CSI camera port for connecting a Raspberry Pi camera
¨ DSI display port for connecting a Raspberry Pi touchscreen display
¨ 4-pole stereo output and composite video port
¨ Micro SD port for loading your operating system and storing data
¨ 5V/2.5A DC power input
¨ Power-over-Ethernet (PoE) support (requires separate PoE HAT)
The Raspberry Pi 3 Model B+ is the latest product in the Raspberry Pi 3 range, boasting a 64-bit quad core processor running at 1.4GHz, dual-band 2.4GHz and 5GHz wireless LAN, Bluetooth 4.2/BLE, faster Ethernet, and PoE capability via a separate PoE HAT The dual-band wireless LAN comes with modular compliance certification, allowing the board to be designed into end products with significantly reduced wireless LAN compliance testing, improving both cost and time to market. The Raspberry Pi 3 Model B+ maintains the same mechanical footprint as both the Raspberry Pi 2 Model B and the Raspberry Pi 3 Model B.
MQTT:
Raspberry pi transmit the data to IOT platform using MQTT.
MQTT was invented by Dr Andy Stanford-Clark of IBM, and Arlen Nipper of Arcom (now Eurotech), in 1999.
MQTT stands for MQ Telemetry Transport. It is a publish/subscribe, extremely simple and lightweight messaging protocol, designed for constrained devices and low-bandwidth, high-latency or unreliable networks. The design principles are to minimise network bandwidth and device resource requirements whilst also attempting to ensure reliability and some degree of assurance of delivery. These principles also turn out to make the protocol ideal of the emerging “machine-to-machine” (M2M) or “Internet of Things” world of connected devices, and for mobile applications where bandwidth and battery power are at a premium.
More information is available on: http://mqtt.org/
System Implementation:
System uses hardware comprising of counting unit, WiFi enabled raspberry pi, LED screen. Software has python code to control the flow through raspberry pi and ThingsBoard open source IOT platform.
Block diagram :
Sensor sense the data and send to the raspberry pi. Raspberry pi increment the counter value with the help of python script. Raspberry pi is WiFi enabled and the data transmitted over MQTT to the ThingsBoard dashboard via internet cloud. ThingsBoard provide the user friendly interface. User has to first create the account on ThingsBoard. All the setup related information is given in reference [7]. User can create the device, dashboard, component linking defining relationship among them. User can also configure and see various type of graphs and can attach to the devices so that analysis becomes easy. User can even set the permission for different customer to different devices. User can also make the device as public so anyone can access the information with the help of given link.
ThingsBoard: Home page
ThingsBoard : Create new device
ThingsBoard: Create new dashboard
Results on ThingsBoard dashboard:
Here two charts for the number of vehicle per minute and number of total vehicle passed with time are shown respectively.
Third chart is a card shows number of vehicle per minute in numerical values.
The python code to upload the data is as follows. Save the code as .py file in your home folder.
#! python3.4
#import all necessary libraries
import paho.mqtt.client as mqtt
import time,json
import time
import RPi.GPIO as GPIO
import json
import array
#define raspberry pi GPIO pins as input or output
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3 , GPIO.IN) # set GPIO25 as input (button)
GPIO.setup(7 , GPIO.OUT)
#global num_of_veh
#global num_of_veh_per_min
num_of_veh = 0
num_of_veh_per_min= 0
def on_log(client, userdata, level, buf):
print(buf)
def on_connect(client, userdata, flags, rc):
if rc==0:
client.connected_flag=True #set flag
print("connected OK")
else:
print("Bad connection Returned code=",rc)
client.loop_stop()
def on_disconnect(client, userdata, rc):
print("client disconnected ok")
def on_publish(client, userdata, mid):
print("In on_pub callback mid= " ,mid)
count=0
mqtt.Client.connected_flag=False#create flag in class
mqtt.Client.suppress_puback_flag=False
client = mqtt.Client("python1") #create new instance
#client.on_log=on_log
client.on_connect = on_connect
client.on_disconnect = on_disconnect
client.on_publish = on_publish
broker="demo.thingsboard.io"
port =1883
topic="v1/devices/me/telemetry"
#need to edit user name
username="xyx" #device house --- Enter your own user name
password=""
if username !="":
pass
client.username_pw_set(username, password)
client.connect(broker,port) #establish connection
while not client.connected_flag: #wait in loop
client.loop()
time.sleep(.1)
time.sleep(.3)
data=dict()
# set GPIO24 as an output (LED)
#for i in range(100):
while True:
num_of_veh_per_min= 0
for i in range(6000): # the counter is incrementing every 10 mSec. the data is updated every 60 Sec i.e. every 1 min. Hence 6000 * 10 mSec = 1 min
channel=GPIO.wait_for_edge(3, GPIO.RISING, timeout= 10)
# wait if a vehicle passes with a time out of 10mSec - debounce time
if channel is None:
if i%100 == 0: # print the timer value after every second beacuse printing timer value every 10mSec increases delay
print('Data will be uploaded after ',60 - i/100,' Seconds')
else:
num_of_veh = num_of_veh +1 # increment the total number of vehicles
num_of_veh_per_min=num_of_veh_per_min+1 # increment the vehicle per min count
print("Number of vehicle",num_of_veh) # print the total numner of vehicle counted till now
time.sleep(0.01)
data["num_of_veh"]=num_of_veh
data["num_of_veh_per_min"]=num_of_veh_per_min
data_out=json.dumps(data) #create JSON object
print("publish topic",topic, "data out= ",data_out)
ret=client.publish(topic,data_out,0) #publish
client.loop()
client.disconnect()