akenza.io
WebsiteAPI DocumentationWhat's newLogin
  • Overview
  • Getting Started
    • Connect a Device
  • Changelog
  • General
    • Applications
    • Organization context
    • Workspace Context
    • Users
      • User Roles
  • Device Management
    • Managing an organization
      • API keys
      • Users (Organization)
        • Add & removing users from your organization
    • Managing a workspace
      • General Settings
        • Device Lifecycle Reports
        • Workspace properties
        • Occupancy settings
        • Device Setup Assistant
      • Custom fields
      • Tags
      • Users (Workspace)
    • Devices
      • Device
      • Device Simulator
      • Bulk actions
      • Bulk import CSV templates
    • Rules
      • Input
      • Logic blocks
        • Comparison
        • Custom Logic
          • Logic Block Scripting
      • Timed Rules
      • Rule Actions
        • Downlink
    • Data Flows
      • Device Connectors
        • Device Security
          • Using Device Credentials
            • Creating Public/Private Key Pairs
            • Using JSON Web Tokens (JWTs)
              • Python
              • Java
        • HTTP
        • MQTT
        • CoAP
        • LoRaWAN
          • Connectivity Management
          • Swisscom LoRaWAN
          • The Things Network
          • Loriot
          • Actility’s ThingPark Wireless
          • EWZ
          • Cibicom
          • Helium
          • ChirpStack
        • NB-IoT
        • mioty
        • Disruptive Technologies
        • VergeSense
        • Spaceti
        • Haltian
      • Device Types
        • Custom Device Types
          • Uplink
          • Downlink
          • Scripting
        • Library
      • Output Connectors
        • Databases
          • akenza DB
          • InfluxDB
          • SQL Databases
        • Streaming
          • Webhook
          • Azure IoT Hub
          • AWS Kinesis
          • Google Cloud Pub/Sub
          • Apache Kafka
        • Notifications
          • E-Mail
          • SMS
          • Microsoft Teams
          • Slack
    • Custom Components
    • Integrations
    • Reference
      • REST API
        • Filtering
        • Querying Device Data
      • WebSocket API
      • Scripting
        • Stateful Operations
        • Utility Functions
      • Payload Templating
  • Reference
  • Dashboard Builder
    • Managing Dashboards
      • Embedding dashboards
    • Components
      • Map
      • Floorplan
  • Device Setup Assistant
    • Device Setup Assistant - Overview
  • Tutorials
    • BI Tools
      • Grafana Data Source Plugin
      • How to build a dashboard with Retool
      • How to analyze data with AWS QuickSight
    • Devices
      • How to integrate the XDK device from Legic via MQTT on akenza
      • How to connect the Disruptive Technologies-cloud on akenza
      • How to send Downlinks to the Kuando Busylight device
      • How to integrate an Arduino device via MQTT on akenza
      • Integrate a MClimate Vicki LoRaWAN Radiator Thermostat on akenza
      • How to integrate an ERS Elsys device with Loriot on akenza
      • How to integrate the IAM Decentlab device with TTN on akenza
      • How to integrate the Seeed SenseCAP T1000 tracker on akenza
      • How to integrate a Swisscom Multisense device on akenza
    • Notifications
      • How to send SMS notifications
      • How to send notifications to Slack
      • How to send notifications to Microsoft Teams
    • Enterprise solutions
      • How to send data to Azure IoT Hub
      • How to send data to the Google Cloud Pub/Sub
      • How to send data to InfluxDB
      • How to send data to AWS Kinesis
      • How to send data to Azure Event Hubs with Apache Kafka
    • IoT Starter Kits
      • How to integrate the IAQ Kit with Actility on akenza
      • How to integrate the CoWork Kit with Actility on akenza
      • How to integrate the Smart Building Kit with Actility on akenza
      • How to integrate the Pepperl+Fuchs Kit with Actility on akenza
  • Support Center
    • FAQ
    • Status Page
    • Service Desk
    • Request a feature
  • Deprecated
    • SIM-Cards
    • Everynet
    • Sigfox
    • How to connect the Yanzi Lifecycle cloud on akenza
Powered by GitBook
On this page
  • Bit Utility Functions
  • Hex to Bits
  • Bits to Hex
  • Base64 to Bits
  • Bits to Base64
  • Bits to Signed Integer
  • Bits to Unsigned Integer
  • Number to Bits
  • Hex Utility Functions
  • Hex to Bytes
  • Bytes to Hex
  • Hex Little Endian to Big Endian Number

Was this helpful?

  1. Device Management
  2. Reference
  3. Scripting

Utility Functions

Akenza provides utility functions which contain commonly used functionality for e.g. converting hex strings into a bit string and vice-versa.

These functions are useful in device types if the uplink payload is hex or base64 encoded or even a bit string representation.

Bit Utility Functions

Bit utility functions provide already implemented logic to convert and manipulate bit represenations to numbers or hexadecimal strings and vice-versa.

Hex to Bits

Usage

Bits.hexToBits(hex: string): string

Examples

Bits.hexToBits('DEADBEEF') -> '11011110101011011011111011101111'

Bits.hexToBits('0xaa') -> '10101010'

Details

This function converts a hex string to a bit string in big endian format.

The hex string can be prefixed with 0x but it is not required.

Throws an error if the hex string does not contain valid hexadecimal characters (0-9a-fA-F).

Bits to Hex

Usage

Bits.bitsToHex(bits: string): string

Examples

Bits.bitsToHex('11011110101011011011111011101111') -> 'DEADBEEF'

Bits.bitsToHex('10101010') -> 'AA'

Details

This function converts a bit string into a hex string. The resulting hex string does not contain the prefix 0x.

The bit representation has to be in big endian format. Otherwise the results will differ.

Throws an error if the bit string is invalid (it may only consist of 1s and 0s).

Base64 to Bits

Usage

Bits.base64ToBits(base64: string): string

Examples

Bits.base64ToBits('Zm9vIA==') -> '01100110011011110110111100100000'

Bits.base64ToBits('YmFy') -> '011000100110000101110010'

Details

This function converts a base64 encoded string into a bit string.

Bits to Base64

Usage

Bits.bitsToBase64(bits: string): string

Examples

Bits.bitsToBase64('01100110011011110110111100100000') -> 'Zm9vIA=='

Bits.bitsToBase64('011000100110000101110010') -> 'YmFy'

Details

This function converts a bit string into a base64 encoded string.

Bits to Signed Integer

Usage

Bits.bitsToSigned(bits: string): number

Examples:

Bits.bitsToSigned('1001') -> -7

Bits.bitsToSigned('0110') -> 6

Details

This function converts a bit string representation of an unsigned integer into an integer.

The bit string representation has to be in big endian format. Otherwise the results will differ.

Throws an error if the bit string is invalid (it may only consist of 1s and 0s).

Bits to Unsigned Integer

Usage

Bits.bitsToUnsigned(bits: string): number

Examples:

Bits.bitsToUnsigned('1001') -> 9

Bits.bitsToUnsigned('0110') -> 6

Details

This function converts a bit string representation of a signed integer into an integer.

The bit string representation has to be in big endian format. Otherwise the results will differ.

Throws an error if the bit string is invalid (it may only consist of 1s and 0s).

Number to Bits

Usage

Bits.numberToBits(value: number, cutOff?: number): string

The function can be invoked with one or two arguments.

The second argument is optional and can either be null or left out completely. If the resulting bit string representation would be smaller than the specified cut off amount, the full bit string representation will be returned, without padding 0s to make up the difference.

Examples:

Bits.numberToBits(123) -> '1111011'

Bits.numberToBits(123, 4) -> '1011'

Bits.numberToBits(123, 16) -> '1111011'

Details

This function converts a number into an unsigned bit-string representation. If the cutOff argument is specified, the resulting string is cut off after the specified amount of bits starting at the LSB. As the resulting bit string is a big endian representation of the number, the cut off point starts from the right hand end of the string up until the specified cut off amount.

Throws an error if an invalid number was provided either for the first or second argument (if present).

Hex Utility Functions

Hex utility functions provide already implemented logic to convert and manipulate hex representations to numbers or byte arrays and vice-versa.

Hex to Bytes

Usage

Hex.hexToBytes(hex: string): number[]

Examples

Hex.hexToBytes('DEADBEEF') -> [222, 173, 190, 239]

Hex.hexToBytes('0xf00ba8') -> [240, 11, 168]

Details

This function converts a hex string into a JS byte array. JS bytes are unsigned integers ranging from 0 - 255.

The hex string can be prefixed with 0x but it is not required.

Throws an error if the hex string does not contain valid hexadecimal characters (0-9a-fA-F).

Bytes to Hex

Usage

Hex.bytesToHex(bytes: number[]): string

Examples

Hex.bytesToHex([222, 173, 190, 239]) -> 'DEADBEEF'

Hex.bytesToHex([240, 11, 168]) -> 'F00BA8'

Details

This function converst an array of JS bytes (numbers from 0 - 255) to a hex string.

Throws an error if the bytes array contains values below 0 or above 255.

Hex Little Endian to Big Endian Number

Usage

Hex.hexLittleEndianToBigEndian(hex: string, signed: boolean): number

Examples:

Hex.hexLittleEndianToBigEndian('AA', false) -> 170

Hex.hexLittleEndianToBigEndian('0xaa', true) -> -86

Details

This function converts the hex string in little endian forma to a big endian number.

The signed param is used to indicate whether the hex representation is a signed or unsigned little endian.

The hex string can be prefixed with 0x but it is not required.

Throws an error if the hex string does not contain valid hexadecimal characters (0-9a-fA-F).

Throws an error if the signed argument is not a valid boolean.

PreviousStateful OperationsNextPayload Templating

Last updated 11 months ago

Was this helpful?

Throws an error if the provided bas64 string is invalid. .

Throws an error if the provided bit string could not successfully be converted to base 64 e.g. the resulting string will contain invalid base64 characters. .

More info about valid base64 characters
More info about valid base64 characters