1. Xiaoke Linux smart home integration temporary supplementary document

  This document addresses third-party integration for Xiaoke products that have relays, such as the L9

1.1. smarthome_preinit parameter passing

  The parameter passing of the smarthome_preinit function adds the number of relay channels switchs_count,

  {"feature":0, "switchs_count":2}

1.2. When the mobile client operates a relay switch, the plugin reports the switch state to the device application layer:

#define DEVICE_SWICTH_1  210
#define DEVICE_SWICTH_2  211

static void slave_on_dp_cb(int i0, int i1) {
  cJSON* root = cJSON_CreateObject();
  cJSON_AddNumberToObject(root, "i0", i0);
  cJSON_AddNumberToObject(root, "i1", i1);
  char* json_str = cJSON_PrintUnformatted(root);
  cJSON_Delete(root);
  g_listener(NULL, PLUGIN_EVENT_SLAVE_CONTROL, json_str);
  free(json_str);
}

slave_on_dp_cb(DEVICE_SWICTH_1+i, dp_bool is the switch state); //relay channel i, i ranges from 0 to 2

1.3. The device application layer controls a relay and notifies the plugin with a message

int smarthome_slave_report(const char* params, callback_func callback) {

  printf("\n\n smarthome_slave_report=%s \n\n", params);

  cJSON* root = cJSON_Parse(params);

  if (root != NULL) {
    int cmd = cJSON_GetObjectItemCaseSensitive(root, "i0")->valueint;
    switch (cmd) {
        case DEVICE_REPORT_DEVICE_PROP: { //relays and the like
            //notify the plugin with the message that operates the relay
          }
          break;

      default:
        break;
    }

    cJSON_Delete(root);
  }

  return 0;
}

1.4. Renaming a relay switch

  After a relay switch is renamed, the application layer has to be notified with PLUGIN_EVENT_ON_DEVICES_SYNC and the devices pulled again, only then can the UI be updated in real time.

#define DEVICE_SWICTH_NAME  215

static void slave_on_dp_cb2(int i0, int i1, char* s0) {
  cJSON* root = cJSON_CreateObject();
  cJSON_AddNumberToObject(root, "i0", i0);
  cJSON_AddNumberToObject(root, "i1", i1);
  cJSON_AddStringToObject(root, "s0", s0);
  char* json_str = cJSON_PrintUnformatted(root);
  cJSON_Delete(root);
  g_listener(NULL, PLUGIN_EVENT_SLAVE_CONTROL, json_str);
  free(json_str);
}

slave_on_dp_cb2(DEVICE_SWICTH_NAME, which relay channel, i1 ranges from 1 to 3, name of the relay switch);

results matching ""

    No results matching ""