Alex Merchen
Created April 10, 2019 © GPL3+

Bus Tracker

Bus Tracker using Soracom Cellular Device, AWS, a couple raspberry pi's and Waveshare E-Ink Display

IntermediateFull instructions provided10 hours1,607
Bus Tracker

Things used in this project

Hardware components

SORACOM Air Global IoT SIM
SORACOM Air Global IoT SIM
×1
Huawei 3G USB dongle (MS2131i)
×1
Jun-Electron for Raspberry Pi 3 B+ 3.5 inch Touch Screen with Case
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Raspberry Pi Zero Wireless
Raspberry Pi Zero Wireless
×1
640x384, 7.5inch E-Ink display HAT
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×1

Software apps and online services

AWS IoT
Amazon Web Services AWS IoT
AWS DynamoDB
Amazon Web Services AWS DynamoDB
SORACOM Air IoT Connectivity Platform
SORACOM Air IoT Connectivity Platform

Story

Read more

Schematics

GitHub Files

Code

Bus Stop code

Python
#!/usr/bin/python
# -*- coding:utf-8 -*-

import epd7in5b
import time
from PIL import Image,ImageDraw,ImageFont
import traceback
import boto3

curMin = 1
curNext = 10

minuteRead = 1
nextRead = 10
	
client = boto3.client(
		'dynamodb',
        'us-east-1',
        aws_access_key_id='YOUR KEY',
        aws_secret_access_key='YOUR OTHER KEY')

#table = conn.get_table('python_test')



try:
    epd = epd7in5b.EPD()
    epd.init()
    print("Clear...")
    epd.Clear(0xFF)
    
    # Drawing on the Horizontal image
    HBlackimage = Image.new('1', (640, 384), 255)  # 298*126
    HRedimage = Image.new('1', (640, 384), 255)  # 298*126    

	
    # Horizontal
    print "Drawing"
    drawblack = ImageDraw.Draw(HBlackimage)
    drawred = ImageDraw.Draw(HRedimage)
    font24 = ImageFont.truetype('/home/pi/Desktop/bcm2835/wqy-microhei.ttc', 24)
    HBlackimage = Image.open('layout.bmp')
    
    while True:
		
		response = client.get_item(
			TableName='BusTrackerTable',
			Key={
				'Row': {
					'S': 'bus_tracker',
				},
				'PositionInRow': {
					'S': 'XXXX',
				},
			})
		
		curMin = response['Item']['payload']['M']['payloads']['M']['Minute']['N']
		curNext = response['Item']['payload']['M']['payloads']['M']['Next']['N']
		
		if (curMin != minuteRead or curNext != nextRead):

			x = str(curMin) + "minutes.bmp" 
			y = str(curNext) + "minutes.bmp" 

			background = Image.open(x)
			foreground = Image.open(y)
			background.paste(foreground, (0,0), foreground)

			HRedimage = background
			
			minuteRead = curMin
			nextRead = curNext
			
			epd.display(epd.getbuffer(HBlackimage), epd.getbuffer(HRedimage))
		
		time.sleep(2)
    
    epd.sleep()
        
except:
    print('traceback.format_exc():\n%s',traceback.format_exc())
    exit()

Bus Location Updater

Python
import tkinter as tk

import requests

headers = {
    'Content-Type': 'application/json',
}

tempV = 3
root = tk.Tk()

mainframe = Frame(root)
mainframe.grid(column=0,row=0, sticky=(N,W,E,S) )
mainframe.columnconfigure(0, weight = 1)
mainframe.rowconfigure(0, weight = 1)
mainframe.pack(pady = 0, padx = 0)

v = tk.IntVar()
v.set(0)  # initializing the choice, i.e. Python

busStops = [
    ("Select Your Current Location"),
    ("Main Street"),
    ("Second Street"),
    ("Third Street"),
    ("Fourth Street"),
    ("Fifth Avenue")
]

def ShowChoice():
    if(v.get() == 1):
        data = '{"Minute":1, "Next":10}'
    elif(v.get() == 2):
        data = '{"Minute":3, "Next":15}'
    elif(v.get() == 3):
        data = '{"Minute":5, "Next":15}'
    elif(v.get() == 4):
        data = '{"Minute":7, "Next":20}'
    elif(v.get() == 5):
        data = '{"Minute":9, "Next":25}'

    response = requests.post('http://funnel.soracom.io', headers=headers, data=data)

for val, busStop in enumerate(busStops):
    tk.Radiobutton(root, 
        text=busStop,
        indicatoron = 0,
        width = 40,
        height = 5,
        padx = 0, 
        variable=v, 
        command=ShowChoice,
        value=val).pack(anchor=tk.N)


root.mainloop()

Credits

Alex Merchen

Alex Merchen

22 projects • 37 followers
I'm an EE with a Masters in ECE. I like building things.

Comments