API for IoT Devices

Public access is provided only for devices that have open access mode enabled. Data can be obtained through HTTP GET requests to the API. Now the device id is used, which is unified for both internal and external use.

Getting the Last N Data Points of a Device

Example request:
https://app.viziot.com/api/v1/public/devices/0df8cb24-3e2b-4046-8464-dac756e70922/points/10

Response: JSON:

{"status":200,"type":"OK","data":[{"dt":1742457275000,","num":{"f1":34,"f2":235.5,"f3":2.89,"f4":630,"f5":6759300,"f6":30.13,},"str":{}}, ...]}

Getting Data for a Period by Unix Timestamp

Example request:
https://app.viziot.com/api/v1/public/devices/0df8cb24-3e2b-4046-8464-dac756e70922/points/1742456275000/1742457275000

Response: JSON:

{"status":200,"type":"OK","data":[{"num":{"f1":34,"f2":234,"f3":2.88,"f4":624,"f5":6759096,"f6":30.92,},"dt":1742456285000,"str":{}}, ... ]}

"Point" Data Type

JavaScript Example

async function getLastPoints(id, count) {
    const url = \`https://app.viziot.com/api/v1/public/devices/\${id}/points/\${count}\`;
    try {
        const response = await fetch(url);
        const data = await response.json();

        switch (data.type) {
            case 'OK':
                console.log('Last points:', data.data);
                break;
            case 'ERROR':
                console.error('Error:', data.description);
                break;
            default:
                console.warn('Unknown response format:', data);
        }
    } catch (err) {
        console.error('Request error:', err);
    }
}

async function getPointsByPeriod(id, ts, te) {
    const url = \`https://app.viziot.com/api/v1/public/devices/\${id}/points/\${ts}/\${te}\`;
    try {
        const response = await fetch(url);
        const data = await response.json();

        switch (data.type) {
            case 'OK':
                console.log('Points for period:', data.data);
                break;
            case 'ERROR':
                console.error('Error:', data.description);
                break;
            default:
                console.warn('Unknown response format:', data);
        }
    } catch (err) {
        console.error('Request error:', err);
    }
}

// Usage example:
const deviceId = "0df8cb24-3e2b-4046-8464-dac756e70922";

getLastPoints(deviceId, 10);

const ts = Math.floor(Date.now()/1000) - 24*60*60;
const te = Math.floor(Date.now()/1000);
getPointsByPeriod(deviceId, ts, te);