Script Error

40 views
Skip to first unread message

Brian

unread,
Sep 21, 2022, 3:05:03 AM9/21/22
to aprs.fi
Hi,
I am attempting to setup a RPi 4 B as to feed AIS messages to APRS.fi. My setup is a Raspberry Pi 4 B with a dASIy HAT feeding date to AIS Dispatcher. When i run the ./ais_json & script, I get error messages.

pi@AISFeeder:~/ais_json $   File "/home/pi/ais_json/./ais_json.py", line 86
    r = requests.post(URL, files={'jsonais': (None, post)})
    ^
IndentationError: expected an indented block

[1]+  Exit 1                  ./ais_json.py

Any idea on a fix?

Thanks,
Brian

Joni Kähärä

unread,
Sep 21, 2022, 12:53:19 PM9/21/22
to aprs.fi
Hello,

What does this Python file contain (in full)?


    Joni OH2EWL

Gregory Badilla

unread,
Oct 26, 2022, 4:23:53 AM10/26/22
to aprs.fi
There was changes on the   pyhton level, if you are using  the old  python script to upload the ais receiver  ( https://github.com/hsiboy/ais_json  ) info it might fail, fortunately there are to change just some pyhton variables.


Check this as reference



or use this:


#!/usr/bin/python

import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
from termcolor import colored
from settings import URL, NAME
import json
import ais.stream
import socket
import datetime
import requests

IP = '127.0.0.1'
PORT = 5000

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((IP, PORT))

while True:

  for msg in ais.stream.decode(sock.makefile('r'),keep_nmea=True):
    rxtime =  datetime.datetime.utcnow().strftime("%Y%m%d%H%M%S") #YYYYMMDDHHMMSS
    parsed = json.loads(json.dumps(msg))
   
    ais = {
            'msgtype': parsed['id'],
            'mmsi': parsed['mmsi'],
            'rxtime': rxtime
            }

    if 'x' in parsed:
      ais['lon'] = parsed['x']
    if 'y' in parsed:
      ais['lat'] = parsed['y']
    if 'sog' in parsed:
      ais['speed'] = parsed['sog']
    if 'cog' in parsed:
      ais['course'] = parsed['cog']
    if 'true_heading' in parsed:
      ais['heading'] = parsed['true_heading']
    if 'nav_status' in parsed:
      ais['status'] = parsed['nav_status']
    if 'type_and_cargo' in parsed:
      ais['shiptype'] = parsed['type_and_cargo']
    if 'part_num' in parsed:
      ais['partno'] = parsed['part_num']
    if 'callsign' in parsed:
      ais['callsign'] = parsed['callsign']
    if 'name' in parsed:
      ais['shipname'] = parsed['name']
    if 'vendor_id' in parsed:
      ais['vendorid'] = parsed['vendor_id']
    if 'dim_a' in parsed:
      ais['ref_front'] = parsed['dim_a']
    if 'dim_c' in parsed:
      ais['ref_left'] = parsed['dim_c']
    if 'draught' in parsed:
      ais['draught'] = parsed['draught']
    if 'length' in parsed:
      ais['length'] = parsed['length']
    if 'width' in parsed:
      ais['width'] = parsed['width']
    if 'destination' in parsed:
      ais['destination'] = parsed['destination']
    if 'persons' in parsed:
      ais['persons_on_board'] = parsed['persons']

    path = {
            "name": NAME,
            "url": URL }

    groups = {
            "path": [path],
            "msgs":[ais] }
   
    output = {
            "encodetime": rxtime,
            "protocol": 'jsonais',
            "groups":  [groups]
            }
   
    post = json.dumps(output)
   #print what's posted
    print (post)
    try:

      r = requests.post(URL, files={'jsonais': (None, post)})
      #dump non common packets for debugging
      if parsed['id'] not in (1,2,3,4):
        print ('Error')
        print (colored('-- Uncommon packet recieved\n', 'red'))
        print (colored('id:', 'green'), parsed['id'])
        print (colored('NMEA:', 'green'), parsed['nmea'])
        print (colored('Parsed:', 'green'), parsed)
        print (colored('Post:', 'green'), post)
        print (colored('Result:', 'green'), json.loads(r.text)['description'])
    except requests.exceptions.RequestException as e:
      print (e)

Heikki Hannikainen

unread,
Nov 21, 2022, 1:53:47 AM11/21/22
to aprs.fi

Hi,

The script below is quite simplistic and may not work well. It uploads
every single location frame with a separate HTTP request, which will
result in aprs.fi rate limiting the requests at times, leading to loss of
data.

It should hold up the data for some 10-15 seconds and send a batch of
frames in a single HTTP post, where a multitude of AIS packets are in the
"msgs":[ais] array.
> Hi,I am attempting to setup a RPi 4 B as to feed AIS messages to APRS.fi. My setup is a Raspberry
> Pi 4 B with a dASIy HAT feeding date to AIS Dispatcher. When i run the ./ais_json & script, I get
> error messages.
>
> pi@AISFeeder:~/ais_json $   File "/home/pi/ais_json/./ais_json.py", line 86
>     r = requests.post(URL, files={'jsonais': (None, post)})
>     ^
> IndentationError: expected an indented block
>
> [1]+  Exit 1                  ./ais_json.py
>
> Any idea on a fix?
>
> Thanks,
> Brian
>
> --
> You received this message because you are subscribed to the Google Groups "aprs.fi" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> aprsfi+un...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/aprsfi/fdc299bc-1062-413b-9488-a7f29a6ba266n%40googlegroups.com.
>
>

- Hessu
Reply all
Reply to author
Forward
0 new messages