Created
April 27, 2021 17:27
-
-
Save Lard4/28c86ae0670ef21da911b4520444c7f0 to your computer and use it in GitHub Desktop.
Lambda printing to stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import awsiot.greengrasscoreipc | |
from awsiot.greengrasscoreipc.model import ( | |
PublishToTopicRequest, | |
PublishMessage, | |
BinaryMessage, | |
QOS, | |
PublishToIoTCoreRequest | |
) | |
import serial | |
import time | |
import sys | |
import logging | |
TIMEOUT = 10 | |
# Setup logging to stdout | |
logger = logging.getLogger(__name__) | |
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) | |
logger.error("doing things!!") | |
print("waiting!!!!", file=sys.stdout, flush=True) | |
ipc_client = awsiot.greengrasscoreipc.connect() | |
future = None | |
print("name is {}".format(__name__), file=sys.stdout, flush=True) | |
def publish_message(message): | |
topic = "gps/raw" | |
request = PublishToIoTCoreRequest() | |
request.topic_name = topic | |
request.payload = bytes(message, "utf-8") | |
request.qos = QOS.AT_LEAST_ONCE | |
operation = ipc_client.new_publish_to_iot_core() | |
operation.activate(request) | |
future = operation.get_response() | |
future.result(TIMEOUT) | |
def main(): | |
print("main loaded", file=sys.stdout, flush=True) | |
serialport = serial.Serial("/dev/ttyAMA1", 9600) | |
while True: | |
print("trying", file=sys.stdout, flush=True) | |
#message = serialport.readline() | |
message = '{"hello":1}' | |
print(message, file=sys.stdout, flush=True) | |
publish_message(message) | |
time.sleep(1) | |
# call main | |
main() | |
def function_handler(event, context): | |
print("function handler", file=sys.stdout, flush=True) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment