void parseTwinMessage()

in mxdevice/Device/utility.cpp [49:86]


void parseTwinMessage(DEVICE_TWIN_UPDATE_STATE updateState, const char *message)
{
  JSON_Value *root_value;
  root_value = json_parse_string(message);
  if (json_value_get_type(root_value) != JSONObject)
  {
    if (root_value != NULL)
    {
      json_value_free(root_value);
    }
    LogError("parse %s failed", message);
    return;
  }

  JSON_Object *root_object = json_value_get_object(root_value);

  double val = 0;
  if (updateState == DEVICE_TWIN_UPDATE_COMPLETE)
  {
    JSON_Object *desired_object = json_object_get_object(root_object, "desired");
    if (desired_object != NULL)
    {
      val = json_object_get_number(desired_object, "interval");
    }
  }
  else
  {
    val = json_object_get_number(root_object, "interval");
  }

  if (val > 500)
  {
    interval = (int)val;
    LogInfo(">>> Device twin updated: set interval to %d", interval);
  }

  json_value_free(root_value);
}