* This is an example, this function needs to be implemented in order to parse the json file into a sql statement
intcount=cJSON_GetArraySize(jPlayload);
* Note that you need to create a super table and database before writing data
for(;i<count;i++)
* In this case:
{
* create database mqttdb;
cJSON*item=cJSON_GetArrayItem(jPlayload,i);
* create table mqttdb.devices(ts timestamp, value bigint) tags(name binary(32), model binary(32), serial binary(16), param binary(16), unit binary(16));
if(cJSON_Object==item->type){
*/
mqttInfo("The item '%s' is not supported",item->string);
}else{
char*mqttConverJsonToSql(char*json,intmaxSize){
strcat(_names,item->string);
// const int32_t maxSize = 10240;
if(i<count-1){
maxSize*=5;
strcat(_names,",");
char*sql=malloc(maxSize);
cJSON*root=cJSON_Parse(json);
if(root==NULL){
mqttError("failed to parse msg, invalid json format");
c1.execute('insert into db.weather values(\"'+stime.Format('yyyy-MM-dd HH:mm:ss.SSS')+'\",'+parseInt(Math.random()*100)+','+parseInt(Math.random()*300)+','+parseFloat(Math.random()*10+30)+',"Note");');
}
}
}
}catch(err){
catch(err){
conn.close();
conn.close();
throwerr;
throwerr;
}
}
...
@@ -98,7 +125,8 @@ catch (err) {
...
@@ -98,7 +125,8 @@ catch (err) {
varretrievedData;
varretrievedData;
try{
try{
c1.query('select * from db.weather limit 5 offset 100;',true).then(function(result){
c1.query('select * from db.weather limit 5 offset 100;',true).then(function(result){
system sh/cfg.sh -n dnode1 -c mnodeEqualVnodeNum -v 4
system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 100000
system sh/cfg.sh -n dnode1 -c http -v 1
system sh/cfg.sh -n dnode1 -c mqtt -v 1
system sh/exec.sh -n dnode1 -s start
sleep 3000
sql connect
sql create database mqttdb;
sql create table mqttdb.devices(ts timestamp, value double) tags(name binary(32), model binary(32), serial binary(16), param binary(16), unit binary(16));