0% found this document useful (0 votes)
19 views4 pages

IOT Phase4

This document discusses three topics: 1) It provides instructions for Phase 4 of a technology project to continue building the project platform using web development technologies and documenting the work. 2) It provides an overview of Microsoft Azure, describing it as a cloud computing platform offering infrastructure, platforms, and software from Microsoft data centers. 3) It includes code samples for displaying real-time transit information using Azure and for interfacing sensor data with Azure using an IoT device client to send telemetry data.

Uploaded by

jaimanirs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

IOT Phase4

This document discusses three topics: 1) It provides instructions for Phase 4 of a technology project to continue building the project platform using web development technologies and documenting the work. 2) It provides an overview of Microsoft Azure, describing it as a cloud computing platform offering infrastructure, platforms, and software from Microsoft data centers. 3) It includes code samples for displaying real-time transit information using Azure and for interfacing sensor data with Azure using an IoT device client to send telemetry data.

Uploaded by

jaimanirs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PHASE 4:

In this technology project you will continue building your project by


developing the platform as per project requirement. Use web development
technologies wherever needed. After performing the relevant activities create
a document around it and share the same for assessment.

ABOUT AZURE:

Azure is Microsoft's cloud computing platform offering a broad range of cloud


services, including infrastructure, platforms, and software. It enables businesses to
build, deploy, and manage applications and services in Microsoft-managed data
centers. Azure supports virtual machines, databases, AI, IoT, and more, with global
data center coverage, robust security, and a pay-as-you-go pricing model. Its
scalability, developer tools, and integration with Microsoft services make it a
popular choice for organizations seeking cloud solutions to drive innovation,
streamline operations, and meet their digital transformation needs.

Code to display Real time Transit Information azure:

pip install requests

import requests
import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:


# Replace with your actual transit API endpoint
api_endpoint = "https://your-transit-api.com/realtime"

# Replace with your API credentials if needed


api_headers = {"Authorization": "Bearer YOUR_API_KEY"}

response = requests.get(api_endpoint, headers=api_headers)

if response.status_code == 200:
transit_data = response.json()
return func.HttpResponse(transit_data, mimetype="application/json")
else:
return func.HttpResponse("Failed to retrieve transit data", status_code=500)
Code for Interfacing Data with Azure:

import machine
import utime
from azure.iot.device import IoTHubDeviceClient, Message

# Define Azure IoT Hub connection string and device ID


CONNECTION_STRING = "HostName=TrafficManagement.azure-
devices.net;DeviceId=RaspPi;SharedAccessKey=7ryCImqSUWqhp5ChKRrkZxNCwpjqtJHL2AIoTGkw
JBs="
DEVICE_ID = "RaspPi"

# Initialize the IoT Hub client


client = IoTHubDeviceClient.create_from_connection_string(CONNECTION_STRING)

# GPIO pins for the HC-SR04 sensor


trigger_pin = machine.Pin(2, machine.Pin.OUT)
echo_pin = machine.Pin(3, machine.Pin.IN)

# Traffic light control pins (simulated)


red_light = machine.Pin(10, machine.Pin.OUT)
yellow_light = machine.Pin(11, machine.Pin.OUT)
green_light = machine.Pin(12, machine.Pin.OUT)

def measure_distance():
trigger_pin.value(0)
utime.sleep_us(2)
trigger_pin.value(1)
utime.sleep_us(10)
trigger_pin.value(0)

while echo_pin.value() == 0:
pulse_start = utime.ticks_us()

while echo_pin.value() == 1:
pulse_end = utime.ticks_us()

pulse_duration = utime.ticks_diff(pulse_end, pulse_start)


distance = (pulse_duration * 0.0343) / 2 # Speed of sound is approximately 343 meters per second

return distance

def control_traffic_lights(distance):
if distance < 10:
red_light.value(0)
yellow_light.value(1)
green_light.value(0)
elif 10 <= distance < 20:
red_light.value(1)
yellow_light.value(0)
green_light.value(0)
else:
red_light.value(0)
yellow_light.value(0)
green_light.value(1)

while True:
distance = measure_distance()
control_traffic_lights(distance)

# For simulation purposes, print the distance and the traffic light state
print("Distance: {:.2f} cm".format(distance))

# Send distance data to IoT Hub


telemetry_data = {"distance_cm": distance}
message = Message(telemetry_data)
client.send_message(message)

utime.sleep(2) # Adjust the sleep duration as needed

Steps we followed while working with Azure:

1) We created an IoT Hub in Microsoft Azure and Deployed it.


2) We created a Device Id, RaspPi and created a Primary Connection
String, by using this, we interfaced it with our Wowki Code, to
establish the web application:

DeviceID: RaspPi
Primary Connection string:HostName=TrafficManagement.azure-
devices.net;DeviceId=RaspPi;SharedAccessKey=7ryCImqSUWqhp5Ch
KRrkZxNCwpjqtJHL2AIoTGkwJBs=

The remaining step is to integrate this code in wokwi, importing


azure.iot.device which is already installed using the command:
pip intall azure-iot-devices

You might also like