update
This commit is contained in:
@@ -136,6 +136,7 @@ class ChatUI {
|
||||
`/chat/${this.currentRoom}`,
|
||||
data,
|
||||
{
|
||||
brokerUrl: window.config.broker_url,
|
||||
fileserverUrl: window.config.fileserver_url,
|
||||
sizeThreshold: window.config.size_threshold
|
||||
}
|
||||
@@ -288,8 +289,8 @@ Let's build a file transfer system that handles large files efficiently.
|
||||
const { smartsend } = require('./NATSBridge');
|
||||
|
||||
class FileUploadService {
|
||||
constructor(natsUrl, fileserverUrl) {
|
||||
this.natsUrl = natsUrl;
|
||||
constructor(brokerUrl, fileserverUrl) {
|
||||
this.brokerUrl = brokerUrl;
|
||||
this.fileserverUrl = fileserverUrl;
|
||||
}
|
||||
|
||||
@@ -308,7 +309,7 @@ class FileUploadService {
|
||||
`/files/${recipient}`,
|
||||
data,
|
||||
{
|
||||
natsUrl: this.natsUrl,
|
||||
brokerUrl: this.brokerUrl,
|
||||
fileserverUrl: this.fileserverUrl,
|
||||
sizeThreshold: 1048576
|
||||
}
|
||||
@@ -419,7 +420,7 @@ async function uploadFile(config) {
|
||||
const filePath = await rl.question('Enter file path: ');
|
||||
const recipient = await rl.question('Enter recipient: ');
|
||||
|
||||
const fileService = new FileUploadService(config.nats_url, config.fileserver_url);
|
||||
const fileService = new FileUploadService(config.broker_url, config.fileserver_url);
|
||||
|
||||
try {
|
||||
const env = await fileService.uploadFile(filePath, recipient);
|
||||
@@ -500,8 +501,8 @@ import time
|
||||
import random
|
||||
|
||||
class SensorSender:
|
||||
def __init__(self, nats_url: str, fileserver_url: str):
|
||||
self.nats_url = nats_url
|
||||
def __init__(self, broker_url: str, fileserver_url: str):
|
||||
self.broker_url = broker_url
|
||||
self.fileserver_url = fileserver_url
|
||||
|
||||
def send_reading(self, sensor_id: str, value: float, unit: str):
|
||||
@@ -518,7 +519,7 @@ class SensorSender:
|
||||
smartsend(
|
||||
f"/sensors/{sensor_id}",
|
||||
data,
|
||||
nats_url=self.nats_url,
|
||||
broker_url=self.broker_url,
|
||||
fileserver_url=self.fileserver_url
|
||||
)
|
||||
|
||||
@@ -537,7 +538,7 @@ class SensorSender:
|
||||
env, env_json_str = smartsend(
|
||||
f"/sensors/{sensor_id}/prepare",
|
||||
data,
|
||||
nats_url=self.nats_url,
|
||||
broker_url=self.broker_url,
|
||||
fileserver_url=self.fileserver_url,
|
||||
is_publish=False
|
||||
)
|
||||
@@ -572,7 +573,7 @@ class SensorSender:
|
||||
smartsend(
|
||||
f"/sensors/batch",
|
||||
data,
|
||||
nats_url=self.nats_url,
|
||||
broker_url=self.broker_url,
|
||||
fileserver_url=self.fileserver_url
|
||||
)
|
||||
else:
|
||||
@@ -631,17 +632,17 @@ Let's build an IoT device using Micropython that connects to NATS.
|
||||
import json
|
||||
|
||||
class DeviceConfig:
|
||||
def __init__(self, ssid, password, nats_url, device_id):
|
||||
def __init__(self, ssid, password, broker_url, device_id):
|
||||
self.ssid = ssid
|
||||
self.password = password
|
||||
self.nats_url = nats_url
|
||||
self.broker_url = broker_url
|
||||
self.device_id = device_id
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
"ssid": self.ssid,
|
||||
"password": self.password,
|
||||
"nats_url": self.nats_url,
|
||||
"broker_url": self.broker_url,
|
||||
"device_id": self.device_id
|
||||
}
|
||||
```
|
||||
@@ -656,7 +657,7 @@ import json
|
||||
class DeviceBridge:
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.nats_url = config.nats_url
|
||||
self.broker_url = config.broker_url
|
||||
|
||||
def connect(self):
|
||||
# Connect to WiFi
|
||||
@@ -676,7 +677,7 @@ class DeviceBridge:
|
||||
smartsend(
|
||||
f"/devices/{self.config.device_id}/status",
|
||||
data,
|
||||
nats_url=self.nats_url
|
||||
broker_url=self.broker_url
|
||||
)
|
||||
|
||||
def send_sensor_data(self, sensor_id, value, unit):
|
||||
@@ -687,7 +688,7 @@ class DeviceBridge:
|
||||
smartsend(
|
||||
f"/devices/{self.config.device_id}/sensors/{sensor_id}",
|
||||
data,
|
||||
nats_url=self.nats_url
|
||||
broker_url=self.broker_url
|
||||
)
|
||||
|
||||
def receive_commands(self, callback):
|
||||
@@ -725,7 +726,7 @@ import random
|
||||
config = DeviceConfig(
|
||||
ssid="MyNetwork",
|
||||
password="password123",
|
||||
nats_url="nats://localhost:4222",
|
||||
broker_url="nats://localhost:4222",
|
||||
device_id="device-001"
|
||||
)
|
||||
|
||||
@@ -774,8 +775,8 @@ import pyarrow as pa
|
||||
import io
|
||||
|
||||
class DashboardServer:
|
||||
def __init__(self, nats_url, fileserver_url):
|
||||
self.nats_url = nats_url
|
||||
def __init__(self, broker_url, fileserver_url):
|
||||
self.broker_url = broker_url
|
||||
self.fileserver_url = fileserver_url
|
||||
|
||||
def broadcast_data(self, df):
|
||||
@@ -792,7 +793,7 @@ class DashboardServer:
|
||||
smartsend(
|
||||
"/dashboard/data",
|
||||
data,
|
||||
nats_url=self.nats_url,
|
||||
broker_url=self.broker_url,
|
||||
fileserver_url=self.fileserver_url
|
||||
)
|
||||
|
||||
@@ -836,6 +837,7 @@ class DashboardUI {
|
||||
const { env, env_json_str } = await smartsend("/dashboard/request", [
|
||||
{ dataname: "request", data: { type: "refresh" }, type: "dictionary" }
|
||||
], {
|
||||
brokerUrl: window.config.broker_url,
|
||||
fileserverUrl: window.config.fileserver_url
|
||||
});
|
||||
}
|
||||
@@ -954,7 +956,7 @@ def send_batch_readings(self, readings):
|
||||
smartsend(
|
||||
"/sensors/batch",
|
||||
[("batch", arrow_data, "table")],
|
||||
nats_url=self.nats_url
|
||||
broker_url=self.broker_url
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user