Show dump1090 data on character lcd


#1

Can anyone show me or point me at a way to show things like aircraft tracked and messages on a character lcd hooked up to a Pi. I already have it wired up and working with test scripts, I’ve just hit a wall on how to get the data from dump1090 to the LCD.

My coding skill is bad and I’m tired of banging on the keyboard on this. Any help is welcome.


#2

If you are using dump1090-mutability, it can write a bunch of json files that have the current aircraft state and various stats.

See github.com/mutability/dump1090/ … ME-json.md


#3

Yup I got that far. Just trying to figure out how to get from this in aircraft.json


{ "now" : 1455992062.5,
  "messages" : 1182944,
  "aircraft" : 
    {"hex":"a6e5b8","altitude":2350,"messages":2,"seen":4.2,"rssi":-18.5},
    {"hex":"a8856d","altitude":11600,"vert_rate":-2176,"track":102,"speed":409,"messages":19,"seen":0.9,"rssi":-19.2},
    {"hex":"a302a0","altitude":9475,"messages":69,"seen":62.6,"rssi":-17.5},
    {"hex":"aab9aa","altitude":23125,"messages":96,"seen":0.0,"rssi":-15.5},
    {"hex":"a5097f","altitude":2100,"messages":51,"seen":149.2,"rssi":-17.7},
  ]
}

To showing the simple aircraft count and message rate on the map page

On the LCD.

I can show the data with this Python script


        import urllib
        import json
        url = "http://192.168.11.101/dump1090/data/aircraft.json"
        data = urllib.urlopen(url).read()
        data = json.loads(data)
        lcd = CharLCD()
        lcd.clear()
        lcd.message("Aircraft: " +str(data'aircraft'])) #Aircraft
        lcd.write4bits(0xC0) #Second Line
        lcd.message("Messages: " +str(data'messages'])) #Messages



Just stumped on how to display a simple count and message rate and not the entire aircraft data section/large message number. Python is not my thing and any help is appreciated.


#4

You’re on the right track.

Try len(data’aircraft’]) for a simple count of aircraft.

For a message rate, you can either

a) read aircraft.json repeatedly and compute the rate from the change in message count over time (this is essentially what the map view does, and can give you a “realtime” value but it is more complex); or

b) read stats.json which will tell you the message count over various periods which is easy to turn directly into a rate, but is a little less realtime since it’s telling you the rate over the last 1 minute period not the rate right now:



  data = # ... load stats.json ...
  interval = data'last1min']'end'] - data'last1min']'start']
  messages = data'last1min']'messages']
  rate = messages / interval



#5

Hi,

i’m using the quick2wire and thinkbowl i2c libraries.
The following python code has proven to be stable. Messages/s are calculated as obj sugested. For the number of Aircrafts the closest match is for me to count the number of Flightnames. len(data’aircraft’]) gives too high numbers.



from i2clibraries import i2c_lcd
from time import *
import urllib.request as ur
import json
import time

# Configuration parameters
# I2C Address, Port, Enable pin, RW pin, RS pin, Data 4 pin, Data 5 pin, Data 6 pin, Data 7 pin, Backlight pin (optional)
lcd = i2c_lcd.i2c_lcd(0x27,1, 2, 1, 0, 4, 5, 6, 7, 3)
url = "http://10.37.4.40/dump1090/data/aircraft.json"
now_old=0
messages_old=0

while True:
  try:
    no_of_aircrafts=0

    data = ur.urlopen(url)
    data_str=data.readall().decode('utf-8')
    data = json.loads(data_str)

    #count aircrafts which have a flight codes for aircraft in data'aircraft']:
      if "flight" in aircraft:
         no_of_aircrafts +=1

    #calculate messages/s      
    now=data'now']
    now_delta=now-now_old;
    messages=data'messages']
    messages_delta=messages-messages_old
    msps=round(messages_delta/now_delta,2)

    # If you want to disable the cursor, uncomment the following line
    lcd.command(lcd.CMD_Display_Control | lcd.OPT_Enable_Display)

    lcd.backLightOn()
    lcd.setPosition(1, 0)

    #format 1st line to 16 length
    string_line1="Aircrafts: "+str(no_of_aircrafts)
    string_line1='{0: <16}'.format(string_line1)   

    lcd.writeString(string_line1)
    lcd.setPosition(2, 0) 

    #format 2nd line to 16 length
    string_line2="Mess./s: " +str(msps)
    string_line2='{0: <16}'.format(string_line2)


    lcd.writeString(string_line2)
    now_old=now
    messages_old=messages
    time.sleep(10)

  #in case of network trouble continue
  except:  
    continue