# Example: refresh info command execution

# Send the operation request to OpenGate

Click bellow to see how to send the operation request to your device.

Using curl
curl 'https://api.opengate.es/north/v80/operation/jobs' \
  -H 'X-ApiKey: your-api-key' \
  -H 'Content-Type: application/json' \
  -H 'Accept: */*' \
  --data '{
  "job": {
    "request": {
      "operationParameters": {
        "timeout": 90000,
        "retries": 0,
        "retriesDelay": 0
      },
      "name": "REFRESH_INFO",
      "schedule": {
        "stop": {
          "delayed": 120000
        }
      },
      "parameters": {},
      "target": {
        "append": {
          "entities": [
            "your-device-id"
          ]
        }
      },
      "active": true
    }
  }
}'

# Receiving operation request into device

You must be connected to OpenGate MQTT connector as subscriber to topic odm/request/your-device-id, if so then you'll receive the an operation request like this:

{
  "operation": {
    "request": {
      "timestamp": 1614239125800,
      "name": "REFRESH_INFO",
      "parameters": {},
      "id": "9ac30d2d-1401-4c2b-996f-e55882b6c5c4"
    }
  }
}

# Answering the operation

Your device must publish a message to the topic odm/response/your-device-id to let know OpenGate it's going to anwer the operation:

{
  "operation": {
    "response": {
      "name": "REFRESH_INFO",
      "timestamp": 1614239127235,
      "resultDescription": "Success",
      "steps": [
        {
          "timestamp": 1614239127235,
          "description": "",
          "name": "REFRESH_INFO",
          "result": "SUCCESSFUL"
        }
      ],
      "deviceId": "your-device-id",
      "resultCode": "SUCCESSFUL",
      "id": "9ac30d2d-1401-4c2b-996f-e55882b6c5c4"
    }
  },
  "version": "1.0"
}

# Fulfill the operation

Because this operation request a full info refresh to your device, it must publish a new message with all the requested information to the topic odm/iot/your-device-id the message:

Click to see an example message
{
  "device": "your-device-id",
  "datastreams": [
    {
      "id": "device.serialNumber",
      "datapoints": [{ "value": "F71SL16NHG9G" }]
    },
    {
      "id": "device.model",
      "datapoints": [
        {
          "value": {
            "name": "OpenGateMqtt",
            "manufacturer": "OpenGate"
          }
        }
      ]
    },
    {
      "id": "device.birthDate",
      "datapoints": [{ "value": "2021-02-25 08:21:32" }]
    },
    {
      "id": "device.operationalStatus",
      "datapoints": [{ "value": "NORMAL" }]
    },
    {
      "id": "device.upTime",
      "datapoints": [{ "value": "1614237191" }]
    },
    {
      "id": "device.clock",
      "datapoints": [
        {
          "value": {
            "date": "2021-02-25",
            "time": "12:32:01"
          }
        }
      ]
    },
    {
      "id": "device.software",
      "datapoints": [
        {
          "value": [
            {
              "type": "FIRMWARE",
              "name": "v1.0.0"
            }
          ]
        }
      ]
    },
    {
      "id": "device.temperature.value",
      "datapoints": [{ "value": 19 }]
    },
    {
      "id": "device.communicationModules[].subscription.identifier",
      "datapoints": [{ "value": "346xxxxxxxx" }]
    },
    {
      "id": "device.communicationModules[].subscription.mobile.signalStrength",
      "datapoints": [{ "value": -80 }]
    },
    {
      "id": "device.communicationModules[].subscription.mobile.signalStrengthStatus",
      "datapoints": [{ "value": "NORMAL" }]
    },
    {
      "id": "device.communicationModules[].subscription.mobile.ratType",
      "datapoints": [{ "value": "LTE" }]
    }
  ],
  "version": "1.0.0"
}