UNPKG

yoctolib-esm

Version:

Yoctopuce library for TypeScript/JavaScript, as an ECMAScript 2015 module

1,265 lines (1,264 loc) 197 kB
/********************************************************************* * * $Id: yocto_api.ts 66046 2025-04-24 09:40:34Z seb $ * * High-level programming interface, common to all modules * * - - - - - - - - - License information: - - - - - - - - - * * Copyright (C) 2011 and beyond by Yoctopuce Sarl, Switzerland. * * Yoctopuce Sarl (hereafter Licensor) grants to you a perpetual * non-exclusive license to use, modify, copy and integrate http * file into your software for the sole purpose of interfacing * with Yoctopuce products. * * You may reproduce and distribute copies of this file in * source or object form, as long as the sole purpose of this * code is to interface with Yoctopuce products. You must retain * this notice in the distributed source file. * * You should refer to Yoctopuce General Terms and Conditions * for additional information regarding your rights and * obligations. * * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING * WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO * EVENT SHALL LICENSOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL, * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR * SERVICES, ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT * LIMITED TO ANY DEFENSE THEREOF), ANY CLAIMS FOR INDEMNITY OR * CONTRIBUTION, OR OTHER SIMILAR COSTS, WHETHER ASSERTED ON THE * BASIS OF CONTRACT, TORT (INCLUDING NEGLIGENCE), BREACH OF * WARRANTY, OR OTHERWISE. * *********************************************************************/ export declare const YAPI_SUCCESS: number; export declare const YAPI_NOT_INITIALIZED: number; export declare const YAPI_INVALID_ARGUMENT: number; export declare const YAPI_NOT_SUPPORTED: number; export declare const YAPI_DEVICE_NOT_FOUND: number; export declare const YAPI_VERSION_MISMATCH: number; export declare const YAPI_DEVICE_BUSY: number; export declare const YAPI_TIMEOUT: number; export declare const YAPI_IO_ERROR: number; export declare const YAPI_NO_MORE_DATA: number; export declare const YAPI_EXHAUSTED: number; export declare const YAPI_DOUBLE_ACCES: number; export declare const YAPI_UNAUTHORIZED: number; export declare const YAPI_RTC_NOT_READY: number; export declare const YAPI_FILE_NOT_FOUND: number; export declare const YAPI_SSL_ERROR: number; export declare const YAPI_RFID_SOFT_ERROR: number; export declare const YAPI_RFID_HARD_ERROR: number; export declare const YAPI_BUFFER_TOO_SMALL: number; export declare const YAPI_DNS_ERROR: number; export declare const YAPI_SSL_UNK_CERT: number; export declare const YAPI_INVALID_INT: number; export declare const YAPI_INVALID_UINT: number; export declare const YAPI_INVALID_LONG: number; export declare const YAPI_INVALID_DOUBLE: number; export declare const YAPI_INVALID_STRING: string; export declare const YAPI_NO_TRUSTED_CA_CHECK: number; export declare const YAPI_NO_EXPIRATION_CHECK: number; export declare const YAPI_NO_HOSTNAME_CHECK: number; export declare const YAPI_LEGACY: number; export declare const YAPI_MIN_DOUBLE: number; export declare const YAPI_MAX_DOUBLE: number; export declare const Y_FUNCTIONDESCRIPTOR_INVALID: string; export declare const Y_DETECT_NONE: number; export declare const Y_DETECT_USB: number; export declare const Y_DETECT_NET: number; export declare const Y_DETECT_ALL: number; export declare class YErrorMsg { msg: string; constructor(msg?: string); } export declare class YoctoError extends Error { errorType?: number; errorMsg?: string; constructor(...params: any[]); } export interface YLogCallback { (msg: string): void; } export interface YProgressCallback { (progress: number, msg: string): void; } export interface yCalibrationHandler { (rawValue: number, calibType: number, parameters: number[], rawValues: number[], refValues: number[]): number; } export interface YHubDiscoveryCallback { (serial: string, urlToRegister: string | null): void; } export interface YDeviceUpdateCallback { (module: YModule): void; } export interface YUnhandledPromiseRejectionCallback { (reason: object, promise: PromiseLike<any>): void; } export type PortInfo = { proto: string; port: number; }; export declare class _YY_UrlInfo { private proto; private user; private pass; private host; private port; private domain; private orgUrl; constructor(str_url: string); imm_getHost(): string; imm_getPass(): string; imm_getPort(): number; imm_getUser(): string; imm_getUrl(withProto?: boolean, withUserPass?: boolean, withEndSlash?: boolean): string; imm_getRootUrl(): string; imm_getProto(): string; imm_useWebSocket(): boolean; /** * @return subdomain (starting with a /) */ imm_getSubDomain(): string; imm_hasAuthParam(): boolean; imm_useSecureSocket(): boolean; imm_testInfoJson(): boolean; imm_updateBestProto(proto: string, port: number): void; imm_updateForRedirect(host: string, port: number, is_secure: boolean): void; imm_updatePortInfo(proto: string, port: number): void; imm_getOriginalURL(): string; imm_updateFrom(urlInfo: _YY_UrlInfo): void; } export interface YConditionalResult { errorType: number; errorMsg: string; result?: string; } export interface YConditionalResultResolver { (result: YConditionalResult): void; } export interface WebSocketCredential { user: string; pass: string; } interface YStringDict { [ident: string]: string; } interface YBoolDict { [ident: string]: boolean; } interface YIntDict { [ident: string]: number; } interface YDeviceDict { [ident: string]: YDevice; } interface YGenericHubDict { [ident: string]: YGenericHub; } interface YHubDict { [ident: string]: YHub; } interface YFunctionTypeDict { [ident: string]: YFunctionType; } interface YDataStreamDict { [ident: string]: YDataStream; } declare class YFunctionType { private _yapi; private _className; private _connectedFns; private _requestedFns; private _hwIdByName; private _nameByHwId; private _valueByHwId; private _baseType; constructor(yapi: YAPIContext, classname: string); /** Index a single function given by HardwareId and logical name; store any advertised value * * @param {string} str_hwid * @param {string} str_name * @param {string|null} str_val * @param {number|null} int_basetype * @returns {boolean} true iff there was a logical name discrepancy */ imm_reindexFunction(str_hwid: string, str_name: string, str_val: string | null, int_basetype: number | null): boolean; /** Forget a disconnected function given by HardwareId * * @param {string} str_hwid */ imm_forgetFunction(str_hwid: string): void; /** Find the exact Hardware Id of the specified function, if currently connected * If device is not known as connected, return a clean error * This function will not cause any network access * * @param {string} str_func * @return {object} */ imm_resolve(str_func: string): YConditionalResult; /** Find the friendly name (use logical name if available) of the specified function, if currently connected * If device is not known as connected, return a clean error * This function will not cause any network access * * @param {string} str_func * @return {object} */ imm_getFriendlyName(str_func: string): YConditionalResult; /** Associates a given function object to a function id * * @param {string} str_func * @param {YFunction} obj_func */ imm_setFunction(str_func: string, obj_func: YFunction): void; /** Retrieve a function object by hardware id, updating the indexes on the fly if needed * * @param {string} str_func * @return {YFunction} */ imm_getFunction(str_func: string): YFunction; /** Stores a function advertised value by hardware id, and tell if an event should be queued for it * * @param {string} str_hwid * @param {string} str_pubval * @return {boolean} */ imm_setFunctionValue(str_hwid: string, str_pubval: string): boolean; /** Retrieve a function advertised value by hardware id * * @param {string} str_hwid * @return {string} */ imm_getFunctionValue(str_hwid: string): string; /** Return the basetype of this function class * * @return {number} */ imm_getBaseType(): number; /** Test if function type is compatible with basetype * * @return {boolean} */ imm_matchBaseType(baseclass: number): boolean; /** Find the hardwareId of the first instance of a given function class * * @return {string|null} */ imm_getFirstHardwareId(): string | null; /** Find the hardwareId for the next instance of a given function class * * @param {string} str_hwid * @return {string|null} */ imm_getNextHardwareId(str_hwid: string): string | null; } export interface YDownloadProgressCallback { (curr: number, total: number): void; } export declare class YHTTPBody { fname: string; data: Uint8Array; progressCb: YDownloadProgressCallback | null; /** Object storing a file to upload * * @param str_fname {string} * @param bin_data {Uint8Array} * @param fun_progressCb {YDownloadProgressCallback} */ constructor(str_fname: string, bin_data: Uint8Array, fun_progressCb: YDownloadProgressCallback | null); } export declare class YHTTPRequest { devUrl: string | null; errorType: number; errorMsg: string; bin_result: Uint8Array | null; obj_result: any; asyncId: number; acceptor: Function | null; toBeSent: Uint8Array | null; sendPos: number; progressCb: YDownloadProgressCallback | null; timeoutId: any; sendTimeoutId: any; next: YHTTPRequest | null; _creat: string; _sent: string; /** Object storing the result of any HTTP Query, with status code and error message * * @param bin_res {Uint8Array} * @param int_errType {number} * @param str_errMsg {string} */ constructor(bin_res: Uint8Array | null, int_errType?: number, str_errMsg?: string); } interface _YY_FuncCache { _expiration: number; [funcAttr: string]: object | number | string; } interface _YY_FuncReq extends _YY_FuncCache { device: YDevice; deviceid: string; functionid: string; hwid: string; } declare class YFuncRequest { obj_result: _YY_FuncReq | null; errorType: number; errorMsg: string; constructor(obj_res: _YY_FuncReq | null, int_errType?: number, str_errMsg?: string); } interface _YY_Module { serialNumber: string; logicalName: string; productName: string; productId: number; firmwareRelease: string; beacon: number; } interface _YY_WhitePage { serialNumber: string; logicalName: string; productName: string; productId: number; networkUrl: string; beacon: number; index: number; } interface _YY_YellowPage { baseType: number; hardwareId: string; logicalName: string; advertisedValue: string; index: number; } interface _YY_YellowPages { [classname: string]: _YY_YellowPage[]; } interface _YY_Services { whitePages: _YY_WhitePage[]; yellowPages: _YY_YellowPages; } interface _YY_HubApi { module: _YY_Module; services: _YY_Services; } /** * YDataStream Class: Unformatted data sequence * * DataStream objects represent bare recorded measure sequences, * exactly as found within the data logger present on Yoctopuce * sensors. * * In most cases, it is not necessary to use DataStream objects * directly, as the DataSet objects (returned by the * get_recordedData() method from sensors and the * get_dataSets() method from the data logger) provide * a more convenient interface. */ export declare class YDataStream { static DATA_INVALID: number; static DURATION_INVALID: number; DATA_INVALID: number; DURATION_INVALID: number; _yapi: YAPIContext; imm_calhdl: Function | null; _parent: YFunction; _runNo: number; _utcStamp: number; _nCols: number; _nRows: number; _startTime: number; _duration: number; _dataSamplesInterval: number; _firstMeasureDuration: number; _columnNames: string[]; _functionId: string; _isClosed: boolean; _isAvg: boolean; _minVal: number; _avgVal: number; _maxVal: number; _caltyp: number; _calpar: number[]; _calraw: number[]; _calref: number[]; _values: number[][]; _isLoaded: boolean; constructor(obj_parent: YFunction, obj_dataset: YDataSet, encoded: number[]); imm_initFromDataSet(dataset: YDataSet, encoded: number[]): number; imm_parseStream(sdata: Uint8Array): number; imm_wasLoaded(): boolean; imm_get_url(): string; imm_get_baseurl(): string; imm_get_urlsuffix(): string; loadStream(): Promise<number>; imm_decodeVal(w: number): number; imm_decodeAvg(dw: number, count: number): number; isClosed(): Promise<boolean>; /** * Returns the run index of the data stream. A run can be made of * multiple datastreams, for different time intervals. * * @return an unsigned number corresponding to the run index. */ get_runIndex(): Promise<number>; /** * Returns the relative start time of the data stream, measured in seconds. * For recent firmwares, the value is relative to the present time, * which means the value is always negative. * If the device uses a firmware older than version 13000, value is * relative to the start of the time the device was powered on, and * is always positive. * If you need an absolute UTC timestamp, use get_realStartTimeUTC(). * * <b>DEPRECATED</b>: This method has been replaced by get_realStartTimeUTC(). * * @return an unsigned number corresponding to the number of seconds * between the start of the run and the beginning of this data * stream. */ get_startTime(): Promise<number>; /** * Returns the start time of the data stream, relative to the Jan 1, 1970. * If the UTC time was not set in the datalogger at the time of the recording * of this data stream, this method returns 0. * * <b>DEPRECATED</b>: This method has been replaced by get_realStartTimeUTC(). * * @return an unsigned number corresponding to the number of seconds * between the Jan 1, 1970 and the beginning of this data * stream (i.e. Unix time representation of the absolute time). */ get_startTimeUTC(): Promise<number>; /** * Returns the start time of the data stream, relative to the Jan 1, 1970. * If the UTC time was not set in the datalogger at the time of the recording * of this data stream, this method returns 0. * * @return a floating-point number corresponding to the number of seconds * between the Jan 1, 1970 and the beginning of this data * stream (i.e. Unix time representation of the absolute time). */ get_realStartTimeUTC(): Promise<number>; /** * Returns the number of milliseconds between two consecutive * rows of this data stream. By default, the data logger records one row * per second, but the recording frequency can be changed for * each device function * * @return an unsigned number corresponding to a number of milliseconds. */ get_dataSamplesIntervalMs(): Promise<number>; get_dataSamplesInterval(): Promise<number>; get_firstDataSamplesInterval(): Promise<number>; /** * Returns the number of data rows present in this stream. * * If the device uses a firmware older than version 13000, * this method fetches the whole data stream from the device * if not yet done, which can cause a little delay. * * @return an unsigned number corresponding to the number of rows. * * On failure, throws an exception or returns zero. */ get_rowCount(): Promise<number>; /** * Returns the number of data columns present in this stream. * The meaning of the values present in each column can be obtained * using the method get_columnNames(). * * If the device uses a firmware older than version 13000, * this method fetches the whole data stream from the device * if not yet done, which can cause a little delay. * * @return an unsigned number corresponding to the number of columns. * * On failure, throws an exception or returns zero. */ get_columnCount(): Promise<number>; /** * Returns the title (or meaning) of each data column present in this stream. * In most case, the title of the data column is the hardware identifier * of the sensor that produced the data. For streams recorded at a lower * recording rate, the dataLogger stores the min, average and max value * during each measure interval into three columns with suffixes _min, * _avg and _max respectively. * * If the device uses a firmware older than version 13000, * this method fetches the whole data stream from the device * if not yet done, which can cause a little delay. * * @return a list containing as many strings as there are columns in the * data stream. * * On failure, throws an exception or returns an empty array. */ get_columnNames(): Promise<string[]>; /** * Returns the smallest measure observed within this stream. * If the device uses a firmware older than version 13000, * this method will always return YDataStream.DATA_INVALID. * * @return a floating-point number corresponding to the smallest value, * or YDataStream.DATA_INVALID if the stream is not yet complete (still recording). * * On failure, throws an exception or returns YDataStream.DATA_INVALID. */ get_minValue(): Promise<number>; /** * Returns the average of all measures observed within this stream. * If the device uses a firmware older than version 13000, * this method will always return YDataStream.DATA_INVALID. * * @return a floating-point number corresponding to the average value, * or YDataStream.DATA_INVALID if the stream is not yet complete (still recording). * * On failure, throws an exception or returns YDataStream.DATA_INVALID. */ get_averageValue(): Promise<number>; /** * Returns the largest measure observed within this stream. * If the device uses a firmware older than version 13000, * this method will always return YDataStream.DATA_INVALID. * * @return a floating-point number corresponding to the largest value, * or YDataStream.DATA_INVALID if the stream is not yet complete (still recording). * * On failure, throws an exception or returns YDataStream.DATA_INVALID. */ get_maxValue(): Promise<number>; get_realDuration(): Promise<number>; /** * Returns the whole data set contained in the stream, as a bidimensional * table of numbers. * The meaning of the values present in each column can be obtained * using the method get_columnNames(). * * This method fetches the whole data stream from the device, * if not yet done. * * @return a list containing as many elements as there are rows in the * data stream. Each row itself is a list of floating-point * numbers. * * On failure, throws an exception or returns an empty array. */ get_dataRows(): Promise<number[][]>; /** * Returns a single measure from the data stream, specified by its * row and column index. * The meaning of the values present in each column can be obtained * using the method get_columnNames(). * * This method fetches the whole data stream from the device, * if not yet done. * * @param row : row index * @param col : column index * * @return a floating-point number * * On failure, throws an exception or returns YDataStream.DATA_INVALID. */ get_data(row: number, col: number): Promise<number>; } /** * YDataSet Class: Recorded data sequence, as returned by sensor.get_recordedData() * * YDataSet objects make it possible to retrieve a set of recorded measures * for a given sensor and a specified time interval. They can be used * to load data points with a progress report. When the YDataSet object is * instantiated by the sensor.get_recordedData() function, no data is * yet loaded from the module. It is only when the loadMore() * method is called over and over than data will be effectively loaded * from the dataLogger. * * A preview of available measures is available using the function * get_preview() as soon as loadMore() has been called * once. Measures themselves are available using function get_measures() * when loaded by subsequent calls to loadMore(). * * This class can only be used on devices that use a relatively recent firmware, * as YDataSet objects are not supported by firmwares older than version 13000. */ export declare class YDataSet { static DATA_INVALID: number; static DURATION_INVALID: number; static HARDWAREID_INVALID: string; static FUNCTIONID_INVALID: string; static UNIT_INVALID: string; DATA_INVALID: number; DURATION_INVALID: number; HARDWAREID_INVALID: string; FUNCTIONID_INVALID: string; UNIT_INVALID: string; _yapi: YAPIContext; _parent: YFunction; _hardwareId: string; _functionId: string; _unit: string; _bulkLoad: number; _startTimeMs: number; _endTimeMs: number; _progress: number; _calib: number[]; _streams: YDataStream[]; _summary: YMeasure; _preview: YMeasure[]; _measures: YMeasure[]; _summaryMinVal: number; _summaryMaxVal: number; _summaryTotalAvg: number; _summaryTotalTime: number; constructor(obj_parent: YFunction, str_functionId?: string, str_unit?: string, double_startTime?: number, double_endTime?: number); imm_get_functionId(): string; imm_get_calibration(): number[]; loadSummary(data: Uint8Array): Promise<number>; processMore(progress: number, data: Uint8Array): Promise<number>; get_privateDataStreams(): Promise<YDataStream[]>; /** * Returns the unique hardware identifier of the function who performed the measures, * in the form SERIAL.FUNCTIONID. The unique hardware identifier is composed of the * device serial number and of the hardware identifier of the function * (for example THRMCPL1-123456.temperature1) * * @return a string that uniquely identifies the function (ex: THRMCPL1-123456.temperature1) * * On failure, throws an exception or returns YDataSet.HARDWAREID_INVALID. */ get_hardwareId(): Promise<string>; /** * Returns the hardware identifier of the function that performed the measure, * without reference to the module. For example temperature1. * * @return a string that identifies the function (ex: temperature1) */ get_functionId(): Promise<string>; /** * Returns the measuring unit for the measured value. * * @return a string that represents a physical unit. * * On failure, throws an exception or returns YDataSet.UNIT_INVALID. */ get_unit(): Promise<string>; /** * Returns the start time of the dataset, relative to the Jan 1, 1970. * When the YDataSet object is created, the start time is the value passed * in parameter to the get_dataSet() function. After the * very first call to loadMore(), the start time is updated * to reflect the timestamp of the first measure actually found in the * dataLogger within the specified range. * * <b>DEPRECATED</b>: This method has been replaced by get_summary() * which contain more precise informations. * * @return an unsigned number corresponding to the number of seconds * between the Jan 1, 1970 and the beginning of this data * set (i.e. Unix time representation of the absolute time). */ get_startTimeUTC(): Promise<number>; imm_get_startTimeUTC(): number; /** * Returns the end time of the dataset, relative to the Jan 1, 1970. * When the YDataSet object is created, the end time is the value passed * in parameter to the get_dataSet() function. After the * very first call to loadMore(), the end time is updated * to reflect the timestamp of the last measure actually found in the * dataLogger within the specified range. * * <b>DEPRECATED</b>: This method has been replaced by get_summary() * which contain more precise informations. * * @return an unsigned number corresponding to the number of seconds * between the Jan 1, 1970 and the end of this data * set (i.e. Unix time representation of the absolute time). */ get_endTimeUTC(): Promise<number>; imm_get_endTimeUTC(): number; /** * Returns the progress of the downloads of the measures from the data logger, * on a scale from 0 to 100. When the object is instantiated by get_dataSet, * the progress is zero. Each time loadMore() is invoked, the progress * is updated, to reach the value 100 only once all measures have been loaded. * * @return an integer in the range 0 to 100 (percentage of completion). */ get_progress(): Promise<number>; /** * Loads the next block of measures from the dataLogger, and updates * the progress indicator. * * @return an integer in the range 0 to 100 (percentage of completion), * or a negative error code in case of failure. * * On failure, throws an exception or returns a negative error code. */ loadMore(): Promise<number>; /** * Returns an YMeasure object which summarizes the whole * YDataSet. In includes the following information: * - the start of a time interval * - the end of a time interval * - the minimal value observed during the time interval * - the average value observed during the time interval * - the maximal value observed during the time interval * * This summary is available as soon as loadMore() has * been called for the first time. * * @return an YMeasure object */ get_summary(): Promise<YMeasure>; /** * Returns a condensed version of the measures that can * retrieved in this YDataSet, as a list of YMeasure * objects. Each item includes: * - the start of a time interval * - the end of a time interval * - the minimal value observed during the time interval * - the average value observed during the time interval * - the maximal value observed during the time interval * * This preview is available as soon as loadMore() has * been called for the first time. * * @return a table of records, where each record depicts the * measured values during a time interval * * On failure, throws an exception or returns an empty array. */ get_preview(): Promise<YMeasure[]>; /** * Returns the detailed set of measures for the time interval corresponding * to a given condensed measures previously returned by get_preview(). * The result is provided as a list of YMeasure objects. * * @param measure : condensed measure from the list previously returned by * get_preview(). * * @return a table of records, where each record depicts the * measured values during a time interval * * On failure, throws an exception or returns an empty array. */ get_measuresAt(measure: YMeasure): Promise<YMeasure[]>; /** * Returns all measured values currently available for this DataSet, * as a list of YMeasure objects. Each item includes: * - the start of the measure time interval * - the end of the measure time interval * - the minimal value observed during the time interval * - the average value observed during the time interval * - the maximal value observed during the time interval * * Before calling this method, you should call loadMore() * to load data from the device. You may have to call loadMore() * several time until all rows are loaded, but you can start * looking at available data rows before the load is complete. * * The oldest measures are always loaded first, and the most * recent measures will be loaded last. As a result, timestamps * are normally sorted in ascending order within the measure table, * unless there was an unexpected adjustment of the datalogger UTC * clock. * * @return a table of records, where each record depicts the * measured value for a given time interval * * On failure, throws an exception or returns an empty array. */ get_measures(): Promise<YMeasure[]>; _parse(str_json: string): Promise<number>; } /** * YConsolidatedDataSet Class: Cross-sensor consolidated data sequence. * * YConsolidatedDataSet objects make it possible to retrieve a set of * recorded measures from multiple sensors, for a specified time interval. * They can be used to load data points progressively, and to receive * data records by timestamp, one by one.. */ export declare class YConsolidatedDataSet { _start: number; _end: number; _nsensors: number; _sensors: YSensor[]; _datasets: YDataSet[]; _progresss: number[]; _nextidx: number[]; _nexttim: number[]; constructor(double_startTime: number, double_endTime: number, obj_sensorList: YSensor[]); imm_init(startt: number, endt: number, sensorList: YSensor[]): number; /** * Returns an object holding historical data for multiple * sensors, for a specified time interval. * The measures will be retrieved from the data logger, which must have been turned * on at the desired time. The resulting object makes it possible to load progressively * a large set of measures from multiple sensors, consolidating data on the fly * to align records based on measurement timestamps. * * @param sensorNames : array of logical names or hardware identifiers of the sensors * for which data must be loaded from their data logger. * @param startTime : the start of the desired measure time interval, * as a Unix timestamp, i.e. the number of seconds since * January 1, 1970 UTC. The special value 0 can be used * to include any measure, without initial limit. * @param endTime : the end of the desired measure time interval, * as a Unix timestamp, i.e. the number of seconds since * January 1, 1970 UTC. The special value 0 can be used * to include any measure, without ending limit. * * @return an instance of YConsolidatedDataSet, providing access to * consolidated historical data. Records can be loaded progressively * using the YConsolidatedDataSet.nextRecord() method. */ static Init(sensorNames: string[], startTime: number, endTime: number): YConsolidatedDataSet; /** * Extracts the next data record from the data logger of all sensors linked to this * object. * * @param datarec : array of floating point numbers, that will be filled by the * function with the timestamp of the measure in first position, * followed by the measured value in next positions. * * @return an integer in the range 0 to 100 (percentage of completion), * or a negative error code in case of failure. * * On failure, throws an exception or returns a negative error code. */ nextRecord(datarec: number[]): Promise<number>; } declare class YDevice { _yapi: YAPIContext; _rootUrl: string; _serialNumber: string; _logicalName: string; _productName: string; _productId: number; _beacon: number; _devYdx: number; _lastErrorType: number; _lastErrorMsg: string; _pendingQueries: Promise<void>; private _cache; private _functions; private _busy; private _lastTimeRef; private _lastDuration; private _logCallback; private _logIsPulling; private _logpos; constructor(obj_yapi: YAPIContext, str_rooturl: string, obj_wpRec: _YY_WhitePage | null, obj_ypRecs: _YY_YellowPages | null); _throw(int_errType: number, str_errMsg: string, obj_retVal?: any): any; /** Return the root URL used to access a device (including the trailing slash) * * @returns {string} */ imm_getRootUrl(): string; /** Return the serial number of the device, as found during discovery * * @returns {string} */ imm_getSerialNumber(): string; /** Return the logical name of the device, as found during discovery * * @returns {string} */ imm_getLogicalName(): string; getLogicalName(): Promise<string>; /** Return the product name of the device, as found during discovery * * @returns {string} */ imm_getProductName(): string; /** Return the product Id of the device, as found during discovery * * @returns {number} */ imm_getProductId(): number; /** Return the beacon state of the device, as found during discovery * * @returns {number} */ imm_getBeacon(): number; /** Return the beacon state of the device, as found during discovery * * @returns {number} */ getBeacon(): Promise<number>; imm_getLastTimeRef(): number; imm_getLastDuration(): number; imm_triggerLogPull(): void; imm_registerLogCallback(callback: YModule.LogCallback | null): void; /** Return the value of the last timestamp sent by the device, if any * * @param float_timestamp {number} * @param float_duration {number} */ imm_setTimeRef(float_timestamp: number, float_duration: number): void; /** Return the hub-specific devYdx of the device, as found during discovery * * @returns {number} */ imm_getDevYdx(): number; /** Return a string that describes the device (serial number, logical name or root URL) * * @returns {string} */ imm_describe(): string; /** Update device cache and YAPI function lists from yp records * * @param obj_ypRecs {object} */ imm_updateFromYP(obj_ypRecs: _YY_YellowPages): void; /** Update device cache and YAPI function lists accordingly * * @param yreq {YHTTPRequest} * @param loadval {object} */ updateFromReq(yreq: YHTTPRequest, loadval: _YY_HubApi): Promise<void>; imm_dropCache(): void; /** Retrieve the number of functions (beside "module") in the device * * @returns {number} */ imm_functionCount(): number; /** Retrieve the Id of the nth function (beside "module") in the device * * @param int_idx {number} * @returns {string} */ imm_functionId(int_idx: number): string; /** Retrieve the base type of the nth function (beside "module") in the device * * @param int_idx {number} * @returns {string} */ imm_functionBaseType(int_idx: number): string; /** Retrieve the type of the nth function (beside 'module') in the device * * @param int_idx {number} * @returns {string} */ imm_functionType(int_idx: number): string; /** Retrieve the logical name of the nth function (beside "module") in the device * * @param int_idx {number} * @returns {string} */ imm_functionName(int_idx: number): string; /** Retrieve the advertised value of the nth function (beside "module") in the device * * @param int_idx {number} * @returns {string} */ imm_functionValue(int_idx: number): string; /** Retrieve the Id of a function given its funydx (internal function identifier index) * * @param int_funydx {number} * @returns {string} */ imm_functionIdByFunYdx(int_funydx: number): string; /** Map an optimized JZON reply to a previously known JSON structure * * @param jzon {object} * @param json {object} * @returns {object} */ imm_jzon2json(jzon: object, json: object): object; /** Get the whole REST API string for a device, from cache if possible * * @param int_msValidity {number} * @returns {YHTTPRequest} */ requestAPI(int_msValidity: number): Promise<YHTTPRequest>; /** Reload a device API (store in cache), and update YAPI function lists accordingly * * @returns {number} */ refresh(): Promise<number>; waitPendingQueries(): Promise<void>; } /** * YFirmwareFile Class: Object describing a loaded firmware file */ export declare class YFirmwareFile { private _path; private _serial; private _pictype; private _product; private _firmware; private _prog_version; private _ROM_nb_zone; private _FLA_nb_zone; private _ROM_total_size; private _FLA_total_size; private _data; private _zone_ofs; constructor(path: string, serial: string, pictype: string, product: string, firmware: string, prog_version: string, ROM_nb_zone: number, FLA_nb_zone: number, ROM_total_size: number, FLA_total_size: number, data: Uint8Array, zone_ofs: number); /** * Parse the binary buffer provided as input and initialize a new object * returns null if the file is not a valid firmware * * @param path {string} * @param data {Uint8Array} * @param force {boolean} * @return {YFirmwareFile|null} */ static imm_Parse(path: string, data: Uint8Array, force: boolean): YFirmwareFile | null; static imm_progCompatible(prog_version: string): boolean; imm_getSerial(): string; imm_getPictype(): string; imm_getProduct(): string; imm_getFirmwareRelease(): string; imm_getFirmwareReleaseAsInt(): number; imm_getProg_version(): string; imm_getROM_nb_zone(): number; imm_getFLA_nb_zone(): number; imm_getROM_total_size(): number; imm_getFLA_total_size(): number; imm_getData(): Uint8Array; imm_getPath(): string; } /** * YFirmwareUpdate Class: Firmware update process control interface, returned by module.updateFirmware method. * * The YFirmwareUpdate class let you control the firmware update of a Yoctopuce * module. This class should not be instantiate directly, but instances should be retrieved * using the YModule method module.updateFirmware. */ export declare class YFirmwareUpdate { _yapi: YAPIContext; _serial: string; _settings: Uint8Array; _firmwarepath: string; _progress_msg: string; _progress_c: number; _progress: number; _restore_step: number; _force: boolean; constructor(obj_yapi: YAPIContext, str_serial: string, str_path: string, bin_settings: Uint8Array, bool_force: boolean); imm_progress(progress: number, msg: string): void; _processMore_internal(newupdate: number): Promise<number>; static checkFirmware_r(file: string, serial_base: string, force: boolean): Promise<YFirmwareFile | null>; /** * Test if the byn file is valid for this module. It is possible to pass a directory instead of a file. * In that case, this method returns the path of the most recent appropriate byn file. This method will * ignore any firmware older than minrelease. * * @param serial {string} : the serial number of the module to update * @param path {string} : the path of a byn file or a directory that contains byn files * @param minrelease {number} : a positive integer * @param force {boolean} : true to force an update even if the API is below expected revision * * @return {string} : the path of the byn file to use, or an empty string if no byn files matches the requirement * * On failure, returns a string that starts with "error:". */ static CheckFirmwareEx(serial: string, path: string, minrelease: number, force: boolean): Promise<string>; static CheckFirmware_internal(serial: string, path: string, minrelease: number): Promise<string>; static GetAllBootLoadersInContext_internal(yctx: YAPIContext): Promise<string[]>; static GetAllBootLoaders_internal(): Promise<string[]>; _processMore(newupdate: number): Promise<number>; /** * Returns a list of all the modules in "firmware update" mode. * * @return an array of strings containing the serial numbers of devices in "firmware update" mode. */ static GetAllBootLoaders(): Promise<string[]>; /** * Returns a list of all the modules in "firmware update" mode. * * @param yctx : a YAPI context. * * @return an array of strings containing the serial numbers of devices in "firmware update" mode. */ static GetAllBootLoadersInContext(yctx: YAPIContext): Promise<string[]>; /** * Test if the byn file is valid for this module. It is possible to pass a directory instead of a file. * In that case, this method returns the path of the most recent appropriate byn file. This method will * ignore any firmware older than minrelease. * * @param serial : the serial number of the module to update * @param path : the path of a byn file or a directory that contains byn files * @param minrelease : a positive integer * * @return : the path of the byn file to use, or an empty string if no byn files matches the requirement * * On failure, returns a string that starts with "error:". */ static CheckFirmware(serial: string, path: string, minrelease: number): Promise<string>; /** * Returns the progress of the firmware update, on a scale from 0 to 100. When the object is * instantiated, the progress is zero. The value is updated during the firmware update process until * the value of 100 is reached. The 100 value means that the firmware update was completed * successfully. If an error occurs during the firmware update, a negative value is returned, and the * error message can be retrieved with get_progressMessage. * * @return an integer in the range 0 to 100 (percentage of completion) * or a negative error code in case of failure. */ get_progress(): Promise<number>; /** * Returns the last progress message of the firmware update process. If an error occurs during the * firmware update process, the error message is returned * * @return a string with the latest progress message, or the error message. */ get_progressMessage(): Promise<string>; /** * Starts the firmware update process. This method starts the firmware update process in background. This method * returns immediately. You can monitor the progress of the firmware update with the get_progress() * and get_progressMessage() methods. * * @return an integer in the range 0 to 100 (percentage of completion), * or a negative error code in case of failure. * * On failure returns a negative error code. */ startUpdate(): Promise<number>; } /** * YFunction Class: Common function interface * * This is the parent class for all public objects representing device functions documented in * the high-level programming API. This abstract class does all the real job, but without * knowledge of the specific function attributes. * * Instantiating a child class of YFunction does not cause any communication. * The instance simply keeps track of its function identifier, and will dynamically bind * to a matching device at the time it is really being used to read or set an attribute. * In order to allow true hot-plug replacement of one device by another, the binding stay * dynamic through the life of the object. * * The YFunction class implements a generic high-level cache for the attribute values of * the specified function, pre-parsed from the REST API string. */ export declare class YFunction { _yapi: YAPIContext; _className: string; _func: string; _lastErrorType: number; _lastErrorMsg: string; _userData: any; _cache: _YY_FuncCache; _dataStreams: YDataStreamDict; _logicalName: string; _advertisedValue: string; _valueCallbackFunction: YFunction.ValueCallback | null; _cacheExpiration: number; _serial: string; _funId: string; _hwId: string; readonly LOGICALNAME_INVALID: string; readonly ADVERTISEDVALUE_INVALID: string; static readonly LOGICALNAME_INVALID: string; static readonly ADVERTISEDVALUE_INVALID: string; constructor(obj_yapi: YAPIContext, str_func: string); _throw(int_errType: number, str_errMsg: string, obj_retVal?: any): any; isReadOnly_internal(): Promise<boolean>; imm_parseAttr(name: string, val: any): number; /** * Returns the logical name of the function. * * @return a string corresponding to the logical name of the function * * On failure, throws an exception or returns YFunction.LOGICALNAME_INVALID. */ get_logicalName(): Promise<string>; /** * Changes the logical name of the function. You can use yCheckLogicalName() * prior to this call to make sure that your parameter is valid. * Remember to call the saveToFlash() method of the module if the * modification must be kept. * * @param newval : a string corresponding to the logical name of the function * * @return YAPI.SUCCESS if the call succeeds. * * On failure, throws an exception or returns a negative error code. */ set_logicalName(newval: string): Promise<number>; /** * Returns a short string representing the current state of the function. * * @return a string corresponding to a short string representing the current state of the function * * On failure, throws an exception or returns YFunction.ADVERTISEDVALUE_INVALID. */ get_advertisedValue(): Promise<string>; set_advertisedValue(newval: string): Promise<number>; /** * Retrieves a function for a given identifier. * The identifier can be specified using several formats: * * - FunctionLogicalName * - ModuleSerialNumber.FunctionIdentifier * - ModuleSerialNumber.FunctionLogicalName * - ModuleLogicalName.FunctionIdentifier * - ModuleLogicalName.FunctionLogicalName * * * This function does not require that the function is online at the time * it is invoked. The returned object is nevertheless valid. * Use the method YFunction.isOnline() to test if the function is * indeed online at a given time. In case of ambiguity when looking for * a function by logical name, no error is notified: the first instance * found is returned. The search is performed first by hardware name, * then by logical name. * * If a call to this object's is_online() method returns FALSE although * you are certain that the matching device is plugged, make sure that you did * call registerHub() at application initialization time. * * @param func : a string that uniquely characterizes the function, for instance * MyDevice.. * * @return a YFunction object allowing you to drive the function. */ static FindFunction(func: string): YFunction; /** * Retrieves a function for a given identifier in a YAPI context. * The identifier can be specified using several formats: * * - FunctionLogicalName * - ModuleSerialNumber.FunctionIdentifier * - ModuleSerialNumber.FunctionLogicalName * - ModuleLogicalName.FunctionIdentifier * - ModuleLogicalName.FunctionLogicalName * * * This function does not require that the function is online at the time * it is invoked. The returned object is nevertheless valid. * Use the method YFunction.isOnline() to test if the function is * indeed online at a given time. In case of ambiguity when looking for * a function by logical name, no error is notified: the first instance * found is returned. The search is performed first by hardware name, * then by logical name. * * @param yctx : a YAPI context * @param func : a string that uniquely characterizes the function, for instance * MyDevice.. * * @return a YFunction object allowing you to drive the function. */ static FindFunctionInContext(yctx: YAPIContext, func: string): YFunction; /** * Registers the callback function that is invoked on every change of advertised value. * The callback is invoked only during the execution of ySleep or yHandleEvents. * This provides control over the time when the callback is triggered. For good responsiveness, remember to call * one of these two functions periodically. To unregister a callback, pass a null pointer as argument. * * @param callback : the callback function to call, or a null pointer. The callback function should take two * arguments: the function object of which the value has changed, and the character string describing * the new advertised value. * @noreturn */ registerValueCallback(callback: YFunction.ValueCallback | null): Promise<number>;