lib/imperituroard/projects/iot.rb in imperituroard-0.4.8 vs lib/imperituroard/projects/iot.rb in imperituroard-0.4.9
- old
+ new
@@ -106,14 +106,25 @@
begin
added_on_iot_platf = []
if for_insert!=[]
##Logic for IOT Platform connection###
- credentials = mongo_client.get_iot_oceanconnect_credent(login)
- if credentials[:code]==200
- for aaa in for_insert
+ for aaa in for_insert
+
+ #########change 2020.05.11. imperituroard
+ #########replace process for get iot app_id and password from users to profile
+
+ #credentials = mongo_client.get_iot_oceanconnect_credent(login)
+ credentials = mongo_client.get_iot_oceanconn_credent_2(aaa["profile"])
+
+ #########
+
+
+ if credentials[:code] == 200
+
+
begin
dev_name = aaa["imei"].to_s
#get {"model"=>"BGT_PPMC", "ManufacturerID"=>"unknown", "ManufacturerNAME"=>"unknown", "device_type"=>"unknown"}
#from database
@@ -144,25 +155,29 @@
not_processed_list.append({:imei => aaa["imei"], :error => resss})
end
rescue
not_processed_list.append({:imei => aaa["imei"], :error => "Unknown error with insertion imei on IOT platform"})
end
- end
- #########end iot platform logic#######
- if added_on_iot_platf.length != 0
- mongo_client.imei_insert_list(added_on_iot_platf)
- resp_out = {:code => 200, :result => "Data processed", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
+ #########end iot platform logic#######
+
else
- resp_out = {:code => 202, :result => "Empty list. Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
+ resss_err = {:code => 400, :result => "IOT platform credentials not found"}
+ not_processed_list.append({:imei => aaa["imei"], :error => resss_err})
end
- else
- resp_out = {:code => 400, :result => "IOT platform credentials not found"}
+
end
+ if added_on_iot_platf.length != 0
+ mongo_client.imei_insert_list(added_on_iot_platf)
+ resp_out = {:code => 200, :result => "Data processed", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
+ else
+ resp_out = {:code => 202, :result => "Empty list. Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
+ end
+
else
resp_out = {:code => 202, :result => "Nothing for insertion", :body => {:imei_processed => added_on_iot_platf, :error_list => not_processed_list}}
end
rescue
@@ -342,23 +357,35 @@
list_from_iot = self.get_info_by_imeilist_from_iot(login, step1_approved_dict_old)
internal_func.printer_texter({:function => "imei_replace Step6", :list_from_iot => list_from_iot, :description => "data from iot platform by old imei"}, "debug")
#processing data. modifying data on iot platform and mongoDB
- if list_from_iot[:code]=="200"
+ if list_from_iot[:code]=="200" && list_from_iot[:body]["devices"] != nil
for ard in list_from_iot[:body]["devices"]
p ard
new_data_cur_dev = {}
mongo_answer = {}
current_old_dev = ard["deviceInfo"]["nodeId"]
current_device_id = ard["deviceId"]
new_data_cur_dev = ard["deviceInfo"]
new_data_cur_dev["nodeId"] = old_new_translation[current_old_dev.to_i].to_s
- credentials = mongo_client.get_iot_oceanconnect_credent(login)
+ p list_from_iot
+ p "list_from_iot"
+
+ #########change 2020.05.11. imperituroard
+ #########replace process for get iot app_id and password from users to profile
+
+ #credentials = mongo_client.get_iot_oceanconnect_credent(login)
+ info_from_mongo = mongo_client.get_imei_info_from_db([current_old_dev.to_i])
+ credentials = mongo_client.get_iot_oceanconn_credent_2(info_from_mongo[:body][0]["profile"])
+
+ #########
+
+
if credentials[:code]==200
flag_remove=0
flag_create=0
remove_answer = hua_aceanconnect_connector.remove_one_device_from_iot(credentials[:body][:app_id], credentials[:body][:secret], current_device_id)
create_answer = hua_aceanconnect_connector.add_new_device_on_huawei2(credentials[:body][:app_id], credentials[:body][:secret], new_data_cur_dev)
@@ -434,11 +461,18 @@
permiss = mongo_client.check_login_profile_permiss(login, prof_name[:body]["profile"])
if permiss[:code]==200
##Logic for IOT Platform connection###
- credentials = mongo_client.get_iot_oceanconnect_credent(login)
+ #########change 2020.05.11. imperituroard
+ #########replace process for get iot app_id and password from users to profile
+
+ #credentials = mongo_client.get_iot_oceanconnect_credent(login)
+ credentials = mongo_client.get_iot_oceanconn_credent_2(prof_name[:body]["profile"])
+
+ #########
+
resp = {}
if credentials[:code]==200
imei_data = mongo_client.get_imei_info_from_db([imei])
@@ -516,17 +550,25 @@
if prof_name[:code]==200
permiss = mongo_client.check_login_profile_permiss(login, prof_name[:body]["profile"])
if permiss[:code]==200
##Logic for IOT Platform connection###
- credentials = mongo_client.get_iot_oceanconnect_credent(login)
+
+ #########change 2020.05.11. imperituroard
+ #########replace process for get iot app_id and password from users to profile
+
+ #credentials = mongo_client.get_iot_oceanconnect_credent(login)
+ credentials = mongo_client.get_iot_oceanconn_credent_2(prof_name[:body]["profile"])
+
+ #########
+
resp = {}
if credentials[:code]==200
imei_data = mongo_client.get_imei_info_from_db([p[:imei]])
if imei_data[:body]!=[]
- ans =hua_aceanconnect_connector.modify_location_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"], p[:address])
+ ans = hua_aceanconnect_connector.modify_location_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"], p[:address])
internal_func.printer_texter({:function => "device_add_address Step2", :ans => ans, :descrition => "answer from hua IOT", :input => {:did => imei_data[:body][0]["huadata"]["body"]["deviceId"], :appid => credentials[:body][:app_id], :secret => credentials[:body][:secret], :address => p[:address]}}, "debug")
end
end
@@ -698,28 +740,28 @@
:info => ff["info"]
})
data_soapgw.append({:id => ff["profile_id"], :form => ff["form"], :description => ff["description"], :profile => ff["profile"]})
end
- tosoapgw = { :code => 200,
- :result => "Request completed successfully",
- :profiles => data_soapgw
+ tosoapgw = {:code => 200,
+ :result => "Request completed successfully",
+ :profiles => data_soapgw
}
resp_out = {:code => 200, :result => "Request completed successfully", :body => {:data => data_processed, :tosoapgw => tosoapgw}}
else
- tosoapgw = { :code => login_info[:code],
- :result => login_info[:result],
- :profiles => data_soapgw
+ tosoapgw = {:code => login_info[:code],
+ :result => login_info[:result],
+ :profiles => data_soapgw
}
resp_out = {:code => login_info[:code], :result => login_info[:result], :body => {:tosoapgw => tosoapgw}}
end
rescue
- tosoapgw = { :code => 507,
- :result => "Unknown SDK error",
- :profiles => data_soapgw
+ tosoapgw = {:code => 507,
+ :result => "Unknown SDK error",
+ :profiles => data_soapgw
}
resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
end
mongo_client.audit_logger("get_available_prof_2", remote_ip, input_params, resp_out, real_ip)
resp_out
@@ -754,28 +796,28 @@
:info => ff["info"]
})
data_soapgw.append({:name => ff["model"], :form => ff["form"], :description => ff["description"], :type_id => ff["type_id"]})
end
- tosoapgw = { :code => 200,
- :result => "Request completed successfully",
- :types => data_soapgw
+ tosoapgw = {:code => 200,
+ :result => "Request completed successfully",
+ :types => data_soapgw
}
resp_out = {:code => 200, :result => "Request completed successfully", :body => {:data => data_processed, :tosoapgw => tosoapgw}}
else
- tosoapgw = { :code => login_info[:code],
- :result => login_info[:result],
- :types => data_soapgw
+ tosoapgw = {:code => login_info[:code],
+ :result => login_info[:result],
+ :types => data_soapgw
}
resp_out = {:code => login_info[:code], :result => login_info[:result], :body => {:tosoapgw => tosoapgw}}
end
rescue
- tosoapgw = { :code => 507,
- :result => "Unknown SDK error",
- :types => data_soapgw
+ tosoapgw = {:code => 507,
+ :result => "Unknown SDK error",
+ :types => data_soapgw
}
resp_out = {:code => 507, :result => "Unknown SDK error", :body => {:tosoapgw => tosoapgw}}
end
mongo_client.audit_logger("get_available_types_2", remote_ip, input_params, resp_out, real_ip)
resp_out
@@ -840,29 +882,78 @@
output_answ
end
-
-
#additional procedure for checking status on iot platform
def get_info_by_imeilist_from_iot(login, imei_list)
resp_out={}
begin
dev_id_list = []
+ for_process_list = {}
resss = {}
data_from_db = mongo_client.get_imei_info_from_db(imei_list)
p data_from_db
+ profile = 0
for g in data_from_db[:body]
+ p g
+ p "ggggg"
dev_id_list.append(g["huadata"]["body"]["deviceId"])
+
+ if for_process_list[g["profile"]] == nil
+ for_process_list[g["profile"]] = [g["huadata"]["body"]["deviceId"]]
+ else
+ for_process_list[g["profile"]].append(g["huadata"]["body"]["deviceId"])
+ end
+
+ if g["profile"] != nil && g["profile"] != ""
+ profile = g["profile"]
+ end
end
- credentials = mongo_client.get_iot_oceanconnect_credent(login)
- if credentials[:code]==200
- p apid = credentials[:body][:app_id]
- p secre = credentials[:body][:secret]
- resp_out = hua_aceanconnect_connector.quer_dev_query_list(apid, secre, dev_id_list)
+
+ p dev_id_list
+ p "dev_id_list"
+ p for_process_list
+
+ for ard in for_process_list
+ ##Logic for IOT Platform connection###
+
+ #########change 2020.05.11. imperituroard
+ #########replace process for get iot app_id and password from users to profile
+
+ #credentials = mongo_client.get_iot_oceanconnect_credent(login)
+ credentials = mongo_client.get_iot_oceanconn_credent_2(ard[0])
+
+ #########
+
+ if credentials[:code] == 200
+ resp_out[:code] = "200"
+ resp_out[:result] = "Processed"
+ p apid = credentials[:body][:app_id]
+ p secre = credentials[:body][:secret]
+ resp_out_1 = hua_aceanconnect_connector.quer_dev_query_list(apid, secre, ard[1])
+ p resp_out_1
+ p "resp_out_1"
+ p resp_out[:body]
+ p "resp_out[:body][\"devices\"]"
+
+ if resp_out[:body] == nil || resp_out[:body] == {} || resp_out[:body] == {"devices"=>nil}
+ p "step1111"
+ p resp_out_1[:body]["devices"]
+ resp_out[:body] = { 'devices' => resp_out_1[:body]["devices"]}
+ p "step22222"
+ else
+ if resp_out_1[:body]["devices"] != nil
+ resp_out[:body]["devices"] = resp_out[:body]["devices"] + resp_out_1[:body]["devices"]
+ end
+ end
+ end
end
+
+ p resp_out
+ p "resp_out"
+
rescue
resp_out = {:code => "500", :message => "get_info_by_imeilist_from_iot: Something wrong", :body => {"devices" => []}}
end
internal_func.printer_texter(resp_out, "debug")
resp_out
@@ -895,9 +986,8 @@
#p ddd.get_device_type_info_by_model("BGT_PPMC11")
#fff = HuaIot.new("134.17.93.4", "443", "/Users/imperituroard/Desktop/cert.crt", "/Users/imperituroard/Desktop/key.pem")
p hua_aceanconnect_connector.querying_device_id("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "eWllZpHgXgvgDAQlJjWs4QXaR94a", "91234")
end
-
end
\ No newline at end of file