User Tools

Site Tools


kits:gpio:api:data

XT GPIO Kit API Data call

This request returns a JSON object with the current state of all configured inputs and outputs. It can be polled or just called once before opening the server events stream in order to get a starting state as the stream only sends changes.

all json keys are lower case.

Request: http://xtgpio.local/api/data

example output:

{
    "name": "DEV GPIO",
    "format": "F",
    "rssi": -39,
    "cputemp": 123,
    "gpio": [
        {
            "index": 1,
            "name": "GPIO #1",
            "type": 3,
            "dimmable": false,
            "state": true
        },
        {
            "index": 2,
            "name": "GPIO #2",
            "type": 3,
            "dimmable": false,
            "state": true
        },
        {
            "index": 3,
            "name": "GPIO #3",
            "type": 3,
            "dimmable": false,
            "state": true
        },
        {
            "index": 4,
            "name": "GPIO #4",
            "type": 3,
            "dimmable": false,
            "state": true
        },
        {
            “index”:5,
            “name”:”TEMP/HUM Sensor”,
            “type”:21,
            “temp”:76.4,
            “hum”:43
        }
    ],
    "onewire": [
        {
            "id": "FFA181",
            "value": 35.9375,
            "reliability": 100
        }
    ]
}
  • name: The device name as configured on the Settings page.
  • format: The temperature format being used, will be either “F” or “C” Used for 1-wire and DHT-22 sensors if any.
  • rssi: Present only if the send rssi checkbox on the Settings page is turned on. The Wifi Signal Strength as an integer.
  • cputemp: Present only if the send cpu temp checkbox on the Settings page is turned on. Note that this is always sent as F as that is how the API from the CPU returns it.
  • gpio: a list of all the configured gpio pins and their current values or setup. Only those GPIO pins that are set to something other than Unused will be present. Also some GPIO pins that are in use for other devices and so have no info for themselves will not be present. For example if a radio receiver is assigned to a specific pin that will not be included here as it has no value to be displayed.
    • index: required, each entry will always have an index value which is the GPIO number.
    • name: required, each entry will always have a string with the name of the GPIO as set in the GPIO Settings page.
    • type: required, a numerical value giving the type of the GPIO. See the list of GPIO types below.
    • dimmable: a bit confusing but historical related to how XTension sets up units. If this is included and true then the GPIO will have an analog or numerical value. If it is absent or set to false then the GPIO is discrete and will only be on or off.
    • state: for discrete GPIO inputs and outputs the state will be true or false.
    • value: for dimmable or analog numerical GPIO values this will be included with the numerical value appropriate for whatever the input is.
    • temp: for a DHT Temp sensor this will contain the most recent temperature data in the format as set above.
    • hum: for a DHT Temp Sensor this will contain the most recent humidity data.
  • onewire: If one wire is enabled this will contain a list of all currently discovered 1-wire temp sensors on the network.
    • id: the 1-wire ID hashed into a 3 byte hex string. Can be used for addressing and should be unique among sensors. It does not include the portion of the ID that contain the device type or other information.
    • value: the temperature as last read. This will be in the format as shown in the format entry in the root of the json dictionary above.
    • reliability: a calculation based on the number of times lately that the device has either not shown up in a device tree scan or has returned one of the values that are known to be sent when an error has occurred when reading it. This can sometimes show a number less than 0 or more than 100 but I’ll be sorting that out. If this is not always 100% then something could be better with your 1-wire network.

GPIO Types:

The type codes used in the above data to show what the GPIO is configured as:

  • 0 NONE, any endpoint set to unused will have this value internally but will not be included in the list.
  • 1 OUTPUT Low at startup.
  • 2 OUTPUT High at startup.
  • 3 OUTPUT Return to last set value at startup.
  • 4 PWM Output (not currently implemented)
  • 5 DAC Output, an analog voltage output between 0 and 3.3v
  • 6 Input Pullup.
  • 7 Input Pulldown.
  • 8 Input Floating. (not currently implemented)
  • 9 Button Input to GND
  • 10 Switch Input To GND
  • 11 Counter Input To GND
  • 12 Analog Voltage Input 0-1.1v
  • 13 Touch Sensor
  • 14 Capacitance Value
  • 15 Encoder Knob Input 1 A
  • 16 Encoder Knob Input 1 B
  • 17 Encoder Knob Input 2 A
  • 18 Encoder Knob Input 2 B
  • 19 Counter Threshold (currently unimplemented)
  • 20 Analog Input Threshold (currently unimplemented)
  • 21 A DHT Temp/Humidity Sensor
  • 22 433Mhz Receiver
  • 23 IR Receiver
  • 24 Servo Pulse Output
  • 25 Button Input to V+
  • 26 Switch Input to V+
  • 27 Counter Input to V+
kits/gpio/api/data.txt · Last modified: 2023/02/13 14:52 by 127.0.0.1