Notify LINE of location information (Google Maps) with GPS multi-unit SORACOM Edition

What i did

GPS multi-unit SORACOM Edition data is sent to AWS Lambda via SORACOM Funk, and location information is notified using LINE Notify. Location information is a link on Google Maps. The language used is Python.

What is GPS multi-unit SORACOM Edition?

Below, quoted from Official Site

GPS multi-unit SORACOM Edition is a device that can use LTE-M communication, which is a cellular LPWA, with built-in four sensors of "location information (GPS)", "temperature", "humidity", and "acceleration" and a rechargeable battery. is.

See below for more information. What is (Official) GPS Multiunit SORACOM Edition Play with GPS multi-unit SORACOM Edition

What is SORACOM Funk?

It is a service that can directly execute the function of the cloud service. This time, we'll run AWS Lambda.

See below What is (Official) SORACOM Funk I tried using SORACOM Funk.

What is LINE Notify?

Below, from Official Site

Receive notifications from web services on LINE When you link with the web service, you will receive a notification from the official account "LINE Notify" provided by LINE. It can be linked with multiple services, and even groups can receive notifications.

See below Send a message to LINE with Python (LINE Notify)

Call LINE Notify on AWS Lambda

The settings for SORACOM, AWS Lambda, and LINE Notify are omitted.

The following to AWS Lambda. Python 3.6 The time is also notified.

lambda_function.py


import os
import requests
import datetime

def lambda_handler(event, context):
    lat = event['lat']     #latitude
    lon = event['lon']     #longitude

#Get the current date and time(Japan time)
    now = datetime.datetime.now(datetime.timezone(datetime.timedelta(hours=9))) 

#When location information cannot be obtained
    if lat == None or lon == None:
      msg = now.strftime('%Y-%m-%d') + " " + now.strftime('%H:%M:%S') + " " + "Could not get location information"
      line_notify(msg)
      return

#View on Google Maps
    mapurl = "https://maps.google.co.jp/maps?q=" + str(lat) + "," + str(lon)  #for google map
    msg = now.strftime('%Y-%m-%d') + " " + now.strftime('%H:%M:%S') + " " +  "You are here" + " " + mapurl
    line_notify(msg)

#Notify LINE Notify
def line_notify(msg):
    url = "https://notify-api.line.me/api/notify"
    headers = {"Authorization" : "Bearer "+ "<Set LINE TOKEN>"}
    data = {"message" : msg}
    s3 = requests.Session()
    r3 = s3.post(url, data=data, headers=headers)

result

IMG_2719.jpg

If you cannot get the location information,

IMG_2720.jpg

Recommended Posts

Notify LINE of location information (Google Maps) with GPS multi-unit SORACOM Edition
Notify LINE of train operation information
Periodically notify the processing status of Raspberry Pi with python → Google Spreadsheet → LINE
Notify LINE of TV appearance information of your favorite entertainer
I tried to notify the train delay information with LINE Notify
Visualize location information with Basemap
Notify LINE of body temperature from BLE thermometer with Raspberry Pi # 1
Notify LINE of body temperature from BLE thermometer with Raspberry Pi # 2