You are on page 1of 2

Tittle : Simple AWS IoT Connection using water temperature monitoring solution AWS with Lamda

Part – A

1.Here temperature sensor had taken for this simple Aws with Lamda connection

2.The values from sensor build the directed to the data server using Aws with Lamda

3.The messages or transfer to Aws using lamda through data server

4.In Aws client is being directed to connect

5.The client able to view the incoming messages

Part –B

import boto3

import datetime

import time

import math

import json

iot_client=boto3.client('iot-data')

topic = "TempCheckerTopic"

def lambda_handler(event, context):

i=0

while i < 800:

i += 1

# Calculating seconds from midnight

now = datetime.datetime.now()

midnight = now.replace(hour=0, minute=0, second=0, microsecond=0)

seconds = (now - midnight).seconds

# Calculating fake temperature value

temperature = round(math.sin(seconds/600) * 5 + 25, 2)


# Preparing payload

payload = json.dumps({"Iterator": i,

"Temperature": temperature,

"Timestamp": now.timestamp()})

# Publishing to IoT Core

iot_client.publish(topic=topic, payload=payload)

# Waiting for 1 second before next value

time.sleep(1)

return {

'statusCode': 200

Part – C

Output : Temperature History

You might also like