1
|
\mainpage OneNetPostӦ??
|
2
|
\section note1 ????˵??
|
3
|
??Ӧ??ʵ?֣?
|
4
|
- ????????ɼ?ԭʼ???ݼ??????????ϴ?onenet?ƶ???ƽ̨
|
5
|
- ????????OneNetƽ̨ע???豸??
|
6
|
- Http?????????ϴ?
|
7
|
|
8
|
\section note2 ????ģ??
|
9
|
??Ӧ?û???Ϊ????ģ?飺
|
10
|
- Ӧ?ÿ??ģ??
|
11
|
- ??Ȩ???
|
12
|
- ????豸ע??״̬
|
13
|
- ע???豸
|
14
|
- ?????ϴ?
|
15
|
\section note3 ????־
|
16
|
|
17
|
\page pageLog ????־
|
18
|
\section log2 20170508
|
19
|
???? 20170508
|
20
|
\section log1 20170508
|
21
|
|
22
|
\page pageApp Ӧ?ÿ??ģ??
|
23
|
\section app1-1 ????????
|
24
|
????豸???ã???Ȩ??????ע???豸
|
25
|
\section app1-2 ???
|
26
|
- ͨ???ϴ????ݻ???-??Ӧ??ʵ????
|
27
|
- ???ù??????? ??ȡini?ļ???ʽ??????ʱ??չ?ġ?
|
28
|
- ?????߳?
|
29
|
- ??Ϣ???? ֧????Ϣ??Ӧ
|
30
|
- ?ػ????? ??ʱ????Ϣ???ػ????̣??쳣?ж????????˳??????ػ??????Զ?????
|
31
|
- ??־??¼ ֧????־??¼??ͨ??global.h?ļ?ȫ?ֱ?????/?رջ???־ģʽ
|
32
|
\section app1-3 ????
|
33
|
|
34
|
|
35
|
\page post OneNeT??Ȩģ??
|
36
|
\section accredit1-1 ????????
|
37
|
????????
|
38
|
- ʵ?ֶ??豸????Ȩ????
|
39
|
|
40
|
\section accredit1-2 ???
|
41
|
- ??ȡ?豸??Ȩ?룬???豸??Ȩ??????Ȩ
|
42
|
\section accredit1-3 ????
|
43
|
(1) ??ȡ?豸??Ȩ??Ϣ
|
44
|
(2) ?Ƿ???Ȩ????????(3)????????(5)
|
45
|
(3) ??????, ???ڣ????˳?????????(4)
|
46
|
(4) ??ʼ??ִ?г??ɼ?????
|
47
|
(5) ??Ȩ?ѹ??ڣ????˳?????????(4)
|
48
|
\section accredit1-4 ע??
|
49
|
ע?????
|
50
|
- ??ʱ?ж??豸??Ȩ?Ƿ????
|
51
|
\section accredit1-5 ʾ??
|
52
|
ʾ???ο?
|
53
|
|
54
|
\page post OneNeT???ע??ģ??
|
55
|
\section accredit1-1 ????????
|
56
|
????????
|
57
|
- ʵ?ֶ??豸ע?????Ƿ?ע???ж?
|
58
|
|
59
|
\section accredit1-2 ???
|
60
|
- ????˶??豸ע?????
|
61
|
- ???豸???б??
|
62
|
\section accredit1-3 ????
|
63
|
(1) ?????豸
|
64
|
(2) ?????豸????
|
65
|
(3) ?ж??豸?Ƿ?ע?ᣬ??????(6),??????(4)
|
66
|
(4) ?ж??豸??Ϣ?Ƿ???£???????(5),??ת(2)
|
67
|
(5) OneNet?豸????http????????(7)
|
68
|
(6) ??OneNetע???豸
|
69
|
(7) ?жϱ????豸?Ƿ???ɣ????˳?????????(2)
|
70
|
\section accredit1-4 ע??
|
71
|
ע?????
|
72
|
- ???豸ע?????Ψһ?Ժ˲?
|
73
|
\section accredit1-5 ʾ??
|
74
|
<pre>
|
75
|
int COneNetPost::OneNet_CheckDeviceRegist(void)
|
76
|
{
|
77
|
|
78
|
std::map<int, TPostMsgItem>::iterator itPostItem = m_PostItem.begin();
|
79
|
std::map<int, TPostMsgItem>::iterator it;
|
80
|
for (; itPostItem != m_PostItem.end(); itPostItem++)
|
81
|
{
|
82
|
it = m_PostDevice.find(iSid);
|
83
|
if (it == m_PostDevice.end())//?豸δע??
|
84
|
{
|
85
|
OneNet_RegistDevice(itPostItem->second);
|
86
|
}
|
87
|
}
|
88
|
return m_PostDevice.size();
|
89
|
}
|
90
|
</pre>
|
91
|
|
92
|
\page postReg OneNETע??ģ??
|
93
|
\section reg1-1 ????????
|
94
|
????????
|
95
|
- ʹ??POST??????OneNetƽ̨ע???豸??
|
96
|
- ?豸ע??ɹ????Զ????????в???ע????豸??Ϣ???Ա????´?????ʱ???õؼ???豸ע???????
|
97
|
\section reg1-2 ???
|
98
|
- ??????õĴ??????Ƿ?????OneNetƽ̨ע?ᣬ??û??ע??????ƽ̨ע???豸
|
99
|
- ?Ѿ?ע????OneNetƽ̨?????豸??Ϣ
|
100
|
- û??ע?ᣬ??OneNetƽ̨ע??ע???豸
|
101
|
- ?ο? OneNET devices
|
102
|
\section reg1-3 ????
|
103
|
(1) ?????豸
|
104
|
(2) ????ע???豸????
|
105
|
(3) ??ƽ̨????ɾ???豸
|
106
|
(4) ɾ???????豸ע????Ϣ
|
107
|
(5) ?豸??????ɣ?????ת??(2),??ת??(6)
|
108
|
(6) ????豸ע??״̬
|
109
|
(7) ?˳?
|
110
|
\section reg1-4 ע??
|
111
|
ע?????
|
112
|
- ע??ǰ?ȼ???豸?Ƿ??Ѿ?ע??
|
113
|
- ?豸?и???Ҫ??ʱ???????ݿ?
|
114
|
\section reg1-5 ʾ??
|
115
|
ʾ???ο?
|
116
|
//??ƽ̨ע??ע???豸
|
117
|
<pre>
|
118
|
int COneNetPost::OneNet_RegistDevice(TPostMsgItem& item)
|
119
|
{
|
120
|
char postdata[_BUF1K]; //Post???????뻺????????????ƽ̨????Post????
|
121
|
char outdata[_BUF2K]; //Post??????????????????ڴ洢ƽ̨???ص?????
|
122
|
long outlen = 0; //Post???????ݳ??ȣ????ڼ?¼ƽ̨???ص????ݴ?С
|
123
|
|
124
|
int iSid = item.Sid;
|
125
|
int iKind = item.Kind;
|
126
|
int iDevId = 0;
|
127
|
std::string sDevApiKey;
|
128
|
|
129
|
std::string sUrl;
|
130
|
std::string sUrlHeader;
|
131
|
cJSON *nd = NULL;
|
132
|
cJSON *json = NULL;
|
133
|
cJSON *child = NULL;
|
134
|
//ע???豸
|
135
|
sUrl = Format("http://%s:%d/register_de?register_code=%s", m_sPostHost.c_str(), m_iPostPort, m_PostRegCode[item.SubSys].c_str());//URL
|
136
|
sUrlHeader=Format("");//Httpͷ
|
137
|
if (iSid > 0)
|
138
|
sprintf(postdata, "{\"sn\": \"%s-%d\"}", m_sMacID.c_str(), iSid);
|
139
|
else
|
140
|
sprintf(postdata, "{\"sn\": \"%s\"}", m_sMacID.c_str());
|
141
|
if (DoHttpRequest(sUrl.c_str(), sUrlHeader.c_str(), postdata, outdata, &outlen) <= 0)
|
142
|
{
|
143
|
return 0;
|
144
|
}
|
145
|
//????????????
|
146
|
json = cJSON_Parse((const char*)outdata);
|
147
|
nd = cJSON_GetObjectItem(json, "error");
|
148
|
int res = 0;
|
149
|
if (strcmp(nd->valuestring, "succ") != 0)
|
150
|
{
|
151
|
cJSON_Delete(json);
|
152
|
return 0;
|
153
|
}
|
154
|
child = cJSON_GetObjectItem(json, "data");
|
155
|
nd = cJSON_GetObjectItem(child, "device_id");//ȡ???豸ID
|
156
|
iDevId = atol(nd->valuestring);
|
157
|
nd = cJSON_GetObjectItem(child, "key");//ȡ???豸ApiKey
|
158
|
sDevApiKey = nd->valuestring;
|
159
|
strcpy(item.ApiKey, nd->valuestring);
|
160
|
item.DevID = iDevId;
|
161
|
m_PostDevice[iSid] = item;
|
162
|
sprintf(postdata, "insert into tbRegDevDef(DevID, SID, Kind, Type, SubSys, Name, Note, ApiKey, Mask, Ext0, Ext1) \
|
163
|
values(%d, %d, %d, %d, %d, '%s', '%s', '%s', 0, 0, 0)",
|
164
|
item.DevID, item.Sid, item.Kind, item.Type, item.SubSys, item.Name, item.ANote, item.ApiKey);
|
165
|
m_dbCfg->execDML(postdata);
|
166
|
cJSON_Delete(json);
|
167
|
|
168
|
//?????豸??Ϣ
|
169
|
OneNet_UpdateDeviceInfo(item);
|
170
|
|
171
|
return 1;
|
172
|
}
|
173
|
</pre>
|
174
|
\page postOneNet OneNeT?ϴ?ģ??
|
175
|
\section post1-1 ????????
|
176
|
????????
|
177
|
- ???????????ϴ?
|
178
|
- ?????????ϴ?
|
179
|
\section post1-2 ???
|
180
|
- ???????
|
181
|
- ??ѯ????
|
182
|
- ?ϴ?????
|
183
|
- ?ο? OneNeT datapoints
|
184
|
\section post1-3 ????
|
185
|
(1) ??ȡ?豸?б?
|
186
|
(2) ?????豸???ݼ?¼
|
187
|
(3) ????????Ƿ???£?????ת(2),??ת(4)
|
188
|
(4) ?????ݸ???http?????????ϴ?
|
189
|
(5) ?ж??Ƿ??????ɣ?????ת??(6),??ת(2)
|
190
|
(6) ????
|
191
|
\section post1-4 ע??
|
192
|
ע??????
|
193
|
- ???????Ƿ????
|
194
|
- ????????Ƿ????
|
195
|
- ?????ϴ??Ƿ?ɹ?
|
196
|
\section post1-5 ʾ??
|
197
|
ʾ???ο?
|
198
|
//?ϴ???????????
|
199
|
<pre>
|
200
|
std::map<int, TPostMsgItem>::iterator itPostItem = m_PostItem.begin();
|
201
|
std::map<int, std::string>::iterator itDateUpd;
|
202
|
for (; itPostItem != m_PostItem.end(); itPostItem++)//????
|
203
|
{
|
204
|
itDateUpd = m_PostDateUpd.find(itPostItem->second.Sid); //???ݸ???ʱ??
|
205
|
if (itDateUpd == m_PostDateUpd.end())//û????ظ??¼?¼
|
206
|
continue;
|
207
|
sTable = m_PostDbTabName[iType];
|
208
|
if (m_dbDat->tableExists(sTable.c_str()))//???ݱ?????
|
209
|
{
|
210
|
ssql = Format(_T("select * from %s where SID=%d"),sTable.c_str(),iSid);
|
211
|
iqry = m_dbDat->qryExec(ssql.data());
|
212
|
if (!m_dbDat->qryEof(iqry))
|
213
|
{
|
214
|
sDateUpd = m_dbDat->qryFieldStr(iqry, _T("DateUpd"));//???ݸ???ʱ??
|
215
|
if (sDateUpd != itDateUpd->second)//?????и???
|
216
|
{
|
217
|
itDateUpd->second = sDateUpd;
|
218
|
//TODO: ??????ݿ??Ƿ???ڲ?ȡ????Ӧ?????ݣ?Ȼ??????Post????֡
|
219
|
iFieldCount = m_dbDat->qryFieldCount(iqry);
|
220
|
sprintf(postdata,"{");
|
221
|
for(int k=1; k<iFieldCount; k++)
|
222
|
{
|
223
|
sprintf(abuf,"\"%s\":%d,",m_dbDat->qryFieldName(iqry,k), m_dbDat->qryFieldInt(iqry, _T(m_dbDat->qryFieldName(iqry, k))));
|
224
|
strcat(postdata, abuf);
|
225
|
}
|
226
|
strcat(postdata,"}");
|
227
|
sUrl = Format("http://%s:%d/devices/%ld/%s", m_sPostHost.c_str(), m_iPostPort, m_PostDevice[iSid].DevID, m_sPostPath.c_str());
|
228
|
sUrlHeader=Format("api-key:%s", m_PostApiKey[itPostItem->second.SubSys].c_str());
|
229
|
if (DoHttpRequest(sUrl.c_str(), sUrlHeader.c_str(), postdata, outdata, &outlen) <= 0)
|
230
|
{
|
231
|
;
|
232
|
}
|
233
|
}
|
234
|
}
|
235
|
m_dbDat->qryFinalize(iqry);
|
236
|
}
|
237
|
_sleep(1);
|
238
|
}
|
239
|
</pre>
|
240
|
|
241
|
|
242
|
|
243
|
|
244
|
|