import datetime
import json
import time
from spotflow_device import DeviceClient

# Connect to the Platform (starts Device Provisioning if the Device is not already registered)
client = DeviceClient.start(device_id="my-device", provisioning_token="<Your Provisioning Token>", db="spotflow.db")

# Create a sender to the default stream
sender = client.create_stream_sender(stream_group = "default-stream-group", stream = "default-stream")

# Your working code starts here. E.g. read data from your sensors and send it to the platform
for i in range(0, 60):
    # Example: Send sample data to the platform:
    payload = json.dumps({
        "timestamp": datetime.datetime.now().astimezone().isoformat(),
        "temperatureCelsius": 21 + (i * 0.05),
        "humidityPercent": 50 + (i * 0.1)
    })
    sender.send_message(payload.encode())
    print(payload)

    # Pause till next iteration
    time.sleep(5)

# Your working code ends here.