update
This commit is contained in:
@@ -134,7 +134,7 @@ env, env_json_str = smartsend("/chat/room1", data, broker_url="nats://localhost:
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
// Send a text message
|
||||
const data = [["message", "Hello World", "text"]];
|
||||
@@ -158,7 +158,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
|
||||
# Send a text message
|
||||
data = [("message", "Hello World", "text")]
|
||||
@@ -185,7 +185,7 @@ env, env_json_str = await smartsend(
|
||||
#### MicroPython
|
||||
|
||||
```python
|
||||
from natbridge_mpy import NATSBridge
|
||||
from natsbridge_mpy import NATSBridge
|
||||
|
||||
bridge = NATSBridge()
|
||||
|
||||
@@ -218,7 +218,7 @@ end
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
// Receive and process message
|
||||
const env = await NATSBridge.smartreceive(msg, {
|
||||
@@ -233,7 +233,7 @@ for (const [dataname, data, type] of env.payloads) {
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartreceive, fetch_with_backoff
|
||||
from natsbridge import smartreceive, fetch_with_backoff
|
||||
|
||||
# Receive and process message
|
||||
env = await smartreceive(
|
||||
@@ -269,7 +269,7 @@ env, env_json_str = smartsend("/device/config", data, broker_url="nats://localho
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
const config = {
|
||||
wifi_ssid: "MyNetwork",
|
||||
@@ -288,7 +288,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
|
||||
config = {
|
||||
"wifi_ssid": "MyNetwork",
|
||||
@@ -307,7 +307,7 @@ env, env_json_str = await smartsend(
|
||||
#### MicroPython
|
||||
|
||||
```python
|
||||
from natbridge_mpy import NATSBridge
|
||||
from natsbridge_mpy import NATSBridge
|
||||
|
||||
bridge = NATSBridge()
|
||||
|
||||
@@ -342,7 +342,7 @@ env, env_json_str = smartsend("/chat/image", data, broker_url="nats://localhost:
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
const fs = require('fs');
|
||||
|
||||
// Read image file
|
||||
@@ -359,7 +359,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
|
||||
# Read image file
|
||||
with open("image.png", "rb") as f:
|
||||
@@ -376,7 +376,7 @@ env, env_json_str = await smartsend(
|
||||
#### MicroPython
|
||||
|
||||
```python
|
||||
from natbridge_mpy import NATSBridge
|
||||
from natsbridge_mpy import NATSBridge
|
||||
|
||||
bridge = NATSBridge()
|
||||
|
||||
@@ -413,7 +413,7 @@ env, env_json_str = smartsend(
|
||||
#### JavaScript (Requester)
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
// Send command with reply-to
|
||||
const data = [["command", { action: "read_sensor" }, "dictionary"]];
|
||||
@@ -431,7 +431,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python (Requester)
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
|
||||
# Send command with reply-to
|
||||
data = [("command", {"action": "read_sensor"}, "dictionary")]
|
||||
@@ -506,7 +506,7 @@ println("File uploaded to: $(env.payloads[1].data)")
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
// Create large data (> 1MB)
|
||||
const large_data = Buffer.alloc(2_000_000);
|
||||
@@ -530,7 +530,7 @@ console.log("File uploaded to:", env.payloads[0].data);
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
|
||||
# Create large data (> 1MB)
|
||||
import os
|
||||
@@ -552,7 +552,7 @@ print(f"File uploaded to: {env['payloads'][0]['data']}")
|
||||
MicroPython enforces a hard limit of 50KB per payload:
|
||||
|
||||
```python
|
||||
from natbridge_mpy import NATSBridge
|
||||
from natsbridge_mpy import NATSBridge
|
||||
|
||||
bridge = NATSBridge()
|
||||
|
||||
@@ -590,7 +590,7 @@ env, env_json_str = smartsend("/chat/mixed", data, broker_url="nats://localhost:
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
const fs = require('fs');
|
||||
|
||||
const image_data = fs.readFileSync('avatar.png');
|
||||
@@ -610,7 +610,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
|
||||
with open("avatar.png", "rb") as f:
|
||||
image_data = f.read()
|
||||
@@ -652,7 +652,7 @@ env, env_json_str = smartsend("/data/students", data, broker_url="nats://localho
|
||||
#### JavaScript
|
||||
|
||||
```javascript
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
// Create table data (array of objects)
|
||||
const table_data = [
|
||||
@@ -672,7 +672,7 @@ const [env, env_json_str] = await NATSBridge.smartsend(
|
||||
#### Python
|
||||
|
||||
```python
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
import pandas as pd
|
||||
|
||||
# Create DataFrame
|
||||
|
||||
@@ -177,7 +177,7 @@ end
|
||||
|
||||
```javascript
|
||||
// src/chat_ui.js
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
class ChatUI {
|
||||
constructor() {
|
||||
@@ -333,7 +333,7 @@ end
|
||||
|
||||
```javascript
|
||||
// src/chat_handler.js
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
const nats = require('nats');
|
||||
|
||||
class ChatHandler {
|
||||
@@ -393,7 +393,7 @@ module.exports = ChatHandler;
|
||||
# src/chat_handler.py
|
||||
import asyncio
|
||||
from typing import Optional
|
||||
from natbridge import smartreceive, fetch_with_backoff
|
||||
from natsbridge import smartreceive, fetch_with_backoff
|
||||
|
||||
class ChatHandler:
|
||||
def __init__(self, nats_connection):
|
||||
@@ -526,7 +526,7 @@ end
|
||||
|
||||
```javascript
|
||||
// src/file_upload_service.js
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
const fs = require('fs');
|
||||
|
||||
class FileUploadService {
|
||||
@@ -580,7 +580,7 @@ module.exports = FileUploadService;
|
||||
|
||||
```python
|
||||
# src/file_upload_service.py
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
import os
|
||||
|
||||
class FileUploadService:
|
||||
@@ -659,7 +659,7 @@ end
|
||||
|
||||
```javascript
|
||||
// src/file_download_service.js
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
const fs = require('fs');
|
||||
|
||||
class FileDownloadService {
|
||||
@@ -690,7 +690,7 @@ module.exports = FileDownloadService;
|
||||
|
||||
```python
|
||||
# src/file_download_service.py
|
||||
from natbridge import smartreceive, fetch_with_backoff
|
||||
from natsbridge import smartreceive, fetch_with_backoff
|
||||
import os
|
||||
|
||||
class FileDownloadService:
|
||||
@@ -832,7 +832,7 @@ end
|
||||
|
||||
```javascript
|
||||
// src/sensor_data.js
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
|
||||
class SensorReading {
|
||||
constructor(sensorId, value, unit, metadata = {}) {
|
||||
@@ -985,7 +985,7 @@ end
|
||||
|
||||
```javascript
|
||||
// src/sensor_sender.js
|
||||
const NATSBridge = require('./src/natbridge.js');
|
||||
const NATSBridge = require('./src/natsbridge.js');
|
||||
const { SensorReading, SensorBatch } = require('./sensor_data.js');
|
||||
|
||||
class SensorSender {
|
||||
@@ -1069,7 +1069,7 @@ module.exports = SensorSender;
|
||||
|
||||
```python
|
||||
# src/sensor_sender.py
|
||||
from natbridge import smartsend
|
||||
from natsbridge import smartsend
|
||||
from sensor_data import SensorReading, SensorBatch
|
||||
|
||||
class SensorSender:
|
||||
@@ -1282,7 +1282,7 @@ end
|
||||
# Cache file server responses
|
||||
import asyncio
|
||||
import threading
|
||||
from natbridge import fetch_with_backoff
|
||||
from natsbridge import fetch_with_backoff
|
||||
|
||||
file_cache = {}
|
||||
cache_lock = threading.Lock()
|
||||
|
||||
Reference in New Issue
Block a user