[英]Azure Event Hub - How to receive data from sensor via https?
I have a sensor that tracks people coming in and out of the building.我有一个传感器可以跟踪进出建筑物的人。 In every event when someone comes in or out, the sensor sends the data via HTTPS to any URL or IP address I specify.
在每次有人进出时,传感器都会通过 HTTPS 将数据发送到我指定的任何 URL 或 IP 地址。 If I set up my laptop as a webserver that listens for incoming traffic I can receive the data.
如果我将笔记本电脑设置为监听传入流量的网络服务器,我可以接收数据。
What I am trying to do is to go serverless and use Azure Event Hubs.我想要做的是 go 无服务器并使用 Azure 事件中心。 I set up an event hub and run the test by pushing data from my laptop using a python script and I can successfully receive the data.
我设置了一个事件中心并通过使用 python 脚本从我的笔记本电脑推送数据来运行测试,我可以成功接收数据。 Here is the sample code I used to test;
这是我用来测试的示例代码; I'm using the connection string to authenticate.
我正在使用连接字符串进行身份验证。
import time
import os
import uuid
import datetime
import random
import json
from azure.eventhub import EventHubProducerClient, EventData
# This script simulates the production of events for 10 devices.
devices = []
for x in range(0, 10):
devices.append(str(uuid.uuid4()))
# Create a producer client to produce and publish events to the event hub.
producer = EventHubProducerClient.from_connection_string(conn_str="My End Point String", eventhub_name="my eventhub name")
for y in range(0,20): # For each device, produce 20 events.
event_data_batch = producer.create_batch() # Create a batch. You will add events to the batch later.
for dev in devices:
# Create a dummy reading.
reading = {'id': dev, 'timestamp': str(datetime.datetime.utcnow()), 'uv': random.random(), 'temperature': random.randint(70, 100), 'humidity': random.randint(70, 100)}
s = json.dumps(reading) # Convert the reading into a JSON string.
event_data_batch.add(EventData(s)) # Add event data to the batch.
producer.send_batch(event_data_batch) # Send the batch of events to the event hub.
# Close the producer.
producer.close()
On my sensor, I don't have an option for these two things to enter.在我的传感器上,我没有输入这两件事的选项。 I only have the option to enter URL/IP.
我只能选择输入 URL/IP。
Any idea how I can set this up?知道如何设置吗?
I suggest moving data this way: Sensor > Azure Functions HTTP trigger > Azure Event Hubs我建议以这种方式移动数据: Sensor > Azure Functions HTTP trigger > Azure Event Hubs
In summary, your sensor will call an HTTP endpoint hosted on Azure Functions and function will check and transform sensor data before forwarding it to an eventhub.总之,您的传感器将调用托管在 Azure 函数上的 HTTP 端点,并且 function 将在将传感器数据转发到 eventhub 之前对其进行检查和转换。
Here is documentation on HTTP trigger - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=csharp这是有关 HTTP 触发器的文档 - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=csharp
Here is the documentation on Event Hubs output binding - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-output?tabs=csharp这是有关事件中心 output 绑定的文档 - https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-output?tabs=csharp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.