Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@samcorky
Copy link
Contributor

New API endpoint /smib/event/smibhid_sensor_log has been added and will accept POST requests with data in the following JSON format:

[
  {
    "human_timestamp": "2025-04-03T21:42:58Z",
    "data": {
      "SCD30": {
        "relative_humidity": 0,
        "temperature": 0,
        "co2": 0
      },
      "BME280": {
        "pressure": 1019.3,
        "humidity": 48.7,
        "temperature": 20.03
      }
    },
    "timestamp": 1743716578
  },
  {
    "timestamp": 1743791084,
    "data": {
      "SCD30": {
        "co2": 1548.1,
        "temperature": 26.3,
        "relative_humidity": 52.9
      },
      "BME280": {
        "pressure": 632,
        "humidity": 57.64,
        "temperature": 23.05
      }
    },
    "human_timestamp": "2025-04-04T18:24:44Z"
  }
]

The data sub-object can accept any name of "module" and any name of "sensor". Reading values must be INT or FLOAT.

JSON object must be an array (@sjefferson99 let me know if you want this changed)

samcorky and others added 3 commits April 13, 2025 15:54
Separated UI and Sensor log models into distinct API and DB modules. Added new functions to handle sensor log POST requests and save to the database. Updated existing UI log handling for consistency and renamed related files to better reflect their purposes.
Updated `SensorData` and related models to use `RootModel` for improved structure and clarity. Adjusted data serialization in `__init__.py` to use `model_dump()` for compatibility with the new structure.
@samcorky samcorky requested a review from sjefferson99 April 13, 2025 15:14
@samcorky samcorky linked an issue Apr 13, 2025 that may be closed by this pull request
@sjefferson99
Copy link
Member

@sam57719 There are no documentation updates. Where does this data go, how can it be accessed?

@sjefferson99 sjefferson99 requested a review from Copilot April 13, 2025 18:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

@samcorky
Copy link
Contributor Author

@sjefferson99 there is an open issue, #53, that deals with the DB documentation. It's changing for SMIB 2.0 anyway.

It will be in the space_openclose db on the DB UI.

@samcorky
Copy link
Contributor Author

@sjefferson99 your issue with the curl command was due to the fact that the device-hostname heading is missing...

On windows:

curl -X POST http://localhost/smib/event/smibhid_sensor_log ^
 -H "Content-Type: application/json" ^
 -H "device-hostname: steves.wang" ^
 -d "[{\"human_timestamp\": \"2025-04-03T21:42:58Z\", \"data\": {\"SCD30\": {\"relative_humidity\": 0, \"temperature\": 0, \"co2\": 0}, \"BME280\": {\"pressure\": 1019.3, \"humidity\": 48.7, \"temperature\": 20.03}}, \"timestamp\": 1743716578}, {\"timestamp\": 1743791084, \"data\": {\"SCD30\": {\"co2\": 1548.1, \"temperature\": 26.3, \"relative_humidity\": 52.9}, \"BME280\": {\"pressure\": 632, \"humidity\": 57.64, \"temperature\": 23.05}}, \"human_timestamp\": \"2025-04-04T18:24:44Z\"}]"

@sjefferson99
Copy link
Member

OK, I shall test again after putting my Wang in it.

Refactored the extraction of `device_hostname` from request headers into the new `extract_device_hostname` function for better code reuse and readability. Updated related event handlers to use this function.
…d-to-smib' into 278-push-sensor-data-from-smibhid-to-smib
@sjefferson99
Copy link
Member

@sam57719 This now works fine. Will approve when you stick a commit in with the above CURL example in the readme being clear about the required header parameters until we get better smib 2 slack. For me in X weeks time when I go to build the smibhid side and get stuck again.

@samcorky
Copy link
Contributor Author

In my latest commit I made the header optional - for ease of testing, and so that the request handler doesn't just crap out with an unhandled exception

Copy link
Member

@sjefferson99 sjefferson99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally approved after asking a dev to add some documentation... for a month.

@samcorky samcorky merged commit 40d09bc into master May 28, 2025
@samcorky samcorky deleted the 278-push-sensor-data-from-smibhid-to-smib branch May 28, 2025 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Push sensor data from SMIBHID to SMIB

3 participants