3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

最寄りのバス停にバスがあと何分で着くかだけを表示するミニサイネージ(M5Stack、UIFlow)

Last updated at Posted at 2021-12-31

はじめに

最寄りのバス停にバスがあと何分で着くかだけを表示するミニサイネージを作りました

開発環境

  • Windows 10 PC
  • M5Stack

実装

1.M5Stackの初期設定はこちらからお願いします

2.UIFlowでプログラムを書きます

image.png
image.png

main.py
from m5stack import *
from m5ui import *
from uiflow import *
import urequests
import wifiCfg
import json


setScreenColor(0x222222)


response_data = None
json_data = None
j = None
i = None


# Describe this function...
def dosomething():
  global response_data, json_data, j, i
  try:
    req = urequests.request(method='GET', url='https://xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/api/xxxx', headers={})
    response_data = (json.loads((req.text)))['results']
    j = 1
    for i in response_data:
      lcd.print(str(i), 0, (j * 36), 0xffffff)
      j = j + 1
  except:
    lcd.print('API error', 0, 0, 0xffffff)


@timerSch.event('timer1')
def ttimer1():
  global response_data, json_data, j, i
  lcd.clear()
  dosomething()
  pass


lcd.font(lcd.FONT_UNICODE)
with open('/sd/settings.json', 'r') as fs:
  json_data = json.loads((fs.read()))
wifiCfg.doConnect(str((json_data['SSID'])), str((json_data['Password'])))
if wifiCfg.wlan_sta.isconnected():
  dosomething()
  timerSch.run('timer1', 60000, 0x00)
else:
  lcd.print(((str('Not connected to ') + str(str((json_data['SSID']))))), 0, 0, 0xffffff)

3.SDカードからWiFi設定を読み込むようにしています。詳細はこちら

4.GTFS Realtimeを使用してあと何分で着くかを返すAPIを作ってます

追記

  • 乗降指定できるようにした
settings.json
{
    "SSID":"x",
    "Password":"xxxxxxxxx",
    "stop_name_1":"%E7%AB%8B%E7%94%B0%E8%87%AA%E7%84%B6%E5%85%AC%E5%9C%92%E5%85%A5%E5%8F%A3",
    "stop_name_2":"%E6%A1%9C%E7%94%BA%E3%83%90%E3%82%B9%E3%82%BF%E3%83%BC%E3%83%9F%E3%83%8A%E3%83%AB",
    "x-api-key":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

image.png
image.png

main.py
from m5stack import *
from m5ui import *
from uiflow import *
import urequests
import wifiCfg
import json


setScreenColor(0x222222)


response_data = None
json_data = None
j = None
i = None



# Describe this function...
def dosomething():
  global response_data, json_data, j, i
  try:
    req = urequests.request(method='GET', url=(str('https://xxxxxxxxxx.execute-api.ap-northeast-1.amazonaws.com/api/xxxxxxx?stop_name_1=') + str(((str(str((json_data['stop_name_1']))) + str(((str('&stop_name_2=') + str(str((json_data['stop_name_2'])))))))))), headers={'x-api-key':str((json_data['x-api-key']))})
    response_data = (json.loads((req.text)))['results']
    j = 1
    for i in response_data:
      lcd.print(str(i), 0, (j * 36), 0xffffff)
      j = j + 1
  except:
    lcd.print('API error', 0, 0, 0xffffff)


def buttonA_wasPressed():
  global response_data, json_data, j, i
  lcd.clear()
  dosomething()
  pass
btnA.wasPressed(buttonA_wasPressed)

@timerSch.event('timer1')
def ttimer1():
  global response_data, json_data, j, i
  lcd.clear()
  dosomething()
  pass


lcd.font(lcd.FONT_UNICODE)
with open('/sd/settings.json', 'r') as fs:
  json_data = json.loads((fs.read()))
wifiCfg.doConnect(str((json_data['SSID'])), str((json_data['Password'])))
if wifiCfg.wlan_sta.isconnected():
  dosomething()
  timerSch.run('timer1', 60000, 0x00)
else:
  lcd.print(((str('Not connected to ') + str(str((json_data['SSID']))))), 0, 0, 0xffffff)
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?