update
This commit is contained in:
@@ -514,6 +514,7 @@ class SensorSender:
|
||||
|
||||
data = [("reading", reading.to_dict(), "dictionary")]
|
||||
|
||||
# Default: is_publish=True (automatically publishes to NATS)
|
||||
smartsend(
|
||||
f"/sensors/{sensor_id}",
|
||||
data,
|
||||
@@ -521,6 +522,31 @@ class SensorSender:
|
||||
fileserver_url=self.fileserver_url
|
||||
)
|
||||
|
||||
def prepare_message_only(self, sensor_id: str, value: float, unit: str):
|
||||
"""Prepare a message without publishing (is_publish=False)."""
|
||||
reading = SensorReading(
|
||||
sensor_id=sensor_id,
|
||||
timestamp=datetime.now().isoformat(),
|
||||
value=value,
|
||||
unit=unit
|
||||
)
|
||||
|
||||
data = [("reading", reading.to_dict(), "dictionary")]
|
||||
|
||||
# With is_publish=False, returns (envelope, json_str) without publishing
|
||||
env, msg_json_str = smartsend(
|
||||
f"/sensors/{sensor_id}/prepare",
|
||||
data,
|
||||
nats_url=self.nats_url,
|
||||
fileserver_url=self.fileserver_url,
|
||||
is_publish=False
|
||||
)
|
||||
|
||||
# Now you can publish manually using NATS request-reply pattern
|
||||
# nc.request(subject, msg_json_str, reply_to=reply_to_topic)
|
||||
|
||||
return env, msg_json_str
|
||||
|
||||
def send_batch(self, readings: List[SensorReading]):
|
||||
batch = SensorBatch()
|
||||
for reading in readings:
|
||||
|
||||
Reference in New Issue
Block a user