void CVkProto::RetrieveChatInfo(CVkChatInfo *cc) { CMStringA szQuery("return { "); // retrieve title & owner id szQuery.AppendFormat("\"info\": API.messages.getChat({\"chat_id\":%d}),", cc->m_chatid); // retrieve users szQuery.AppendFormat("\"users\": API.messages.getChatUsers({\"chat_id\":%d, \"fields\":\"uid,first_name,last_name\"})", cc->m_chatid); if (!cc->m_bHistoryRead) szQuery.AppendFormat(",\"msgs\": API.messages.getHistory({\"chat_id\":%d, \"count\":\"20\", \"rev\":\"0\"})", cc->m_chatid); szQuery.Append("};"); debugLogA("CVkProto::RetrieveChantInfo(%d)", cc->m_chatid); Push(new AsyncHttpRequest(this, REQUEST_GET, "/method/execute.json", true, &CVkProto::OnReceiveChatInfo) << CHAR_PARAM("code", szQuery))->pUserInfo = cc; }
void MQTT::SendDeviceInfo(const int m_HwdID, const unsigned long long DeviceRowIdx, const std::string &DeviceName, const unsigned char *pRXCommand) { boost::lock_guard<boost::mutex> l(m_mqtt_mutex); if (!m_IsConnected) return; std::vector<std::vector<std::string> > result; result = m_sql.safe_query("SELECT DeviceID, Unit, Name, [Type], SubType, nValue, sValue, SwitchType, SignalLevel, BatteryLevel, Options FROM DeviceStatus WHERE (HardwareID==%d) AND (ID==%llu)", m_HwdID, DeviceRowIdx); if (result.size() > 0) { std::vector<std::string> sd = result[0]; std::string did = sd[0]; int dunit = atoi(sd[1].c_str()); std::string name = sd[2]; int dType = atoi(sd[3].c_str()); int dSubType = atoi(sd[4].c_str()); int nvalue = atoi(sd[5].c_str()); std::string svalue = sd[6]; _eSwitchType switchType = (_eSwitchType)atoi(sd[7].c_str()); int RSSI = atoi(sd[8].c_str()); int BatteryLevel = atoi(sd[9].c_str()); std::map<std::string, std::string> options = m_sql.BuildDeviceOptions(sd[10]); Json::Value root; root["idx"] = DeviceRowIdx; root["id"] = did; root["unit"] = dunit; root["name"] = name; root["dtype"] = RFX_Type_Desc(dType,1); root["stype"] = RFX_Type_SubType_Desc(dType, dSubType); if (IsLightOrSwitch(dType, dSubType) == true) { root["switchType"] = Switch_Type_Desc(switchType); } // Add device options std::map<std::string, std::string>::const_iterator ittOptions; for (ittOptions = options.begin(); ittOptions != options.end(); ++ittOptions) { std::string optionName = ittOptions->first.c_str(); std::string optionValue = ittOptions->second.c_str(); root[optionName] = optionValue; } root["RSSI"] = RSSI; root["Battery"] = BatteryLevel; root["nvalue"] = nvalue; //give all svalues separate std::vector<std::string> strarray; StringSplit(svalue, ";", strarray); std::vector<std::string>::const_iterator itt; int sIndex = 1; for (itt = strarray.begin(); itt != strarray.end(); ++itt) { std::stringstream szQuery(""); szQuery << "svalue" << sIndex; root[szQuery.str()] = *itt; sIndex++; } std::string message = root.toStyledString(); if (m_publish_topics & PT_out) { SendMessage(TOPIC_OUT, message); } if (m_publish_topics & PT_floor_room) { result = m_sql.safe_query("SELECT F.Name, P.Name, M.DeviceRowID FROM Plans as P, Floorplans as F, DeviceToPlansMap as M WHERE P.FloorplanID=F.ID and M.PlanID=P.ID and M.DeviceRowID=='%llu'", DeviceRowIdx); for(size_t i=0 ; i<result.size(); i++) { std::vector<std::string> sd = result[i]; std::string floor = sd[0]; std::string room = sd[1]; std::stringstream topic(""); topic << TOPIC_OUT << "/" << floor << "/" + room; SendMessage(topic.str() , message); } } } }