* This is an example, this function needs to be implemented in order to parse the json file into a sql statement
* Note that you need to create a super table and database before writing data
* In this case:
* create database mqttdb;
* create table mqttdb.devices(ts timestamp, value bigint) tags(name binary(32), model binary(32), serial binary(16), param binary(16), unit binary(16));
*/
char*mqttConverJsonToSql(char*json,intmaxSize){
// const int32_t maxSize = 10240;
maxSize*=5;
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();
throwerr;
}
...
...
@@ -98,7 +125,8 @@ catch (err) {
varretrievedData;
try{
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));