lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb in imperituroard-1.0.4 vs lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb in imperituroard-1.0.5
- old
+ new
@@ -74,11 +74,12 @@
request.body = URI.encode_www_form(data)
res = https.request(request)
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
fff = {:func => "get_token",
:iot_fun => "",
- :req_header => {:content_type => 'application/x-www-form-urlencoded'
+ :req_header => {:content_type => 'application/x-www-form-urlencoded',
+ :platform => "Huawei oceanconnect"
}}
client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
rescue
out_resp = {:code => 500, :message => "failed get token"}
end
@@ -110,11 +111,12 @@
request.content_type = 'application/json'
request.body = URI.encode_www_form(data)
res = https.request(request)
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
fff = {:func => "token_logout",
- :iot_fun => "logout"
+ :iot_fun => "logout",
+ :platform => "Huawei oceanconnect"
}
client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
rescue
out_resp = {:code => 500, :message => "failed logout token"}
end
@@ -123,10 +125,11 @@
out_resp
end
#Registering a Directly Connected Device (Verification Code Mode) (V2)
def dev_register_verif_code_mode(app_id, secret, node_id)
+ out_resp = {}
token = get_token(app_id, secret)[:body]["accessToken"]
path = "/iocm/app/reg/v1.1.0/deviceCredentials?appId=" + app_id
url_string = "https://" + platformip + ":" + platformport + path
uri = URI.parse url_string
https = Net::HTTP.new(uri.host, uri.port)
@@ -136,13 +139,21 @@
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.path)
request.content_type = 'application/json'
request['Authorization'] = 'Bearer ' + token
request['app_key'] = app_id
- request.body = {nodeId: node_id}.to_json
+ data = {nodeId: node_id}
+ request.body = data.to_json
res = https.request(request)
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
+ out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
+ fff = {:func => "dev_register_verif_code_mode",
+ :iot_fun => "Registering a Directly Connected Device (Verification Code Mode) (V2)",
+ :req_header => {:content_type => 'application/json',
+ :platform => "Huawei oceanconnect"
+ }}
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
+ out_resp
end
#2.2.4 Registering a Directly Connected Device (Password Mode) (V2)
def dev_register_passw_code_mode2(app_id, secret, node_id, name_p, description_p, device_type, profile, manufacturer_id, manufacturer_name, model)
out_resp = {}
@@ -174,11 +185,12 @@
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
fff = {:func => "dev_register_passw_code_mode2",
:iot_fun => "2.2.4",
:req_header => {:authorization => 'Bearer ' + token,
:content_type => 'application/json',
- :app_key => app_id
+ :app_key => app_id,
+ :platform => "Huawei oceanconnect"
}}
client_iot_mongo.audit_iot_logger(fff, url_string, data_out, out_resp)
out_resp
end
@@ -197,17 +209,25 @@
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.path)
request.content_type = 'application/json'
request['Authorization'] = 'Bearer ' + token
request['app_key'] = app_id
- data_out = {deviceInfo: attr_list}.to_json
+ data = {deviceInfo: attr_list}
+ data_out = data.to_json
internal_func.printer_texter({:procedure => "dev_register_passw_code_mode2", :data => {:body => data_out, :url => url_string}}, "debug")
request.body = data_out
res = https.request(request)
p res.body.to_s
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
- p out_resp
+ fff = {:func => "dev_reg_passw_code_mode2_2",
+ :iot_fun => "2.2.4",
+ :req_header => {:content_type => 'application/json',
+ :authorization => 'Bearer ' + token,
+ :app_key => app_id,
+ :platform => "Huawei oceanconnect"
+ }}
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, out_resp)
out_resp
end
#2.2.12 Deleting a Directly Connected Device
@@ -235,11 +255,12 @@
end
fff = {:func => "dev_delete",
:iot_fun => "2.2.12",
:req_header => {:authorization => 'Bearer ' + token,
:content_type => 'application/json',
- :app_key => app_id
+ :app_key => app_id,
+ :platform => "Huawei oceanconnect"
}}
client_iot_mongo.audit_iot_logger(fff, url_string, "Delete", out_resp)
rescue
out_resp = {:code => 500, :message => "dev_delete: Unknown IOT error"}
end
@@ -272,10 +293,11 @@
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
end
#2.2.14 Querying Device Activation Status
def querying_device_activ_status(app_id, secret, device_id)
+ output_ans = {}
token = get_token(app_id, secret)[:body]["accessToken"]
path = "/iocm/app/reg/v1.1.0/devices/" + device_id + "?app_Id=" + app_id
url_string = "https://" + platformip + ":" + platformport + path
uri = URI.parse url_string
https = Net::HTTP.new(uri.host, uri.port)
@@ -286,16 +308,26 @@
request = Net::HTTP::Get.new(uri.path)
request.content_type = 'application/json'
request['Authorization'] = 'Bearer ' + token
request['app_key'] = app_id
res = https.request(request)
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
+ output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
+ fff = {:func => "querying_device_activ_status",
+ :iot_fun => "2.2.14",
+ :req_header => {:content_type => 'application/json',
+ :authorization => 'Bearer ' + token,
+ :app_key => app_id,
+ :platform => "Huawei oceanconnect"
+ }}
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, output_ans)
+ output_ans
end
#2.9.1 Querying Information About a Device
def querying_device_info(app_id, secret, device_id)
+ out_resp = {}
token = get_token(app_id, secret)[:body]["accessToken"]
path = "/iocm/app/dm/v1.1.0/devices/" + device_id + "?app_Id=" + app_id
url_string = "https://" + platformip + ":" + platformport + path
uri = URI.parse url_string
https = Net::HTTP.new(uri.host, uri.port)
@@ -306,11 +338,20 @@
request = Net::HTTP::Get.new(uri.path)
request.content_type = 'application/json'
request['Authorization'] = 'Bearer ' + token
request['app_key'] = app_id
res = https.request(request)
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
+ out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
+ fff = {:func => "querying_device_info",
+ :iot_fun => "2.9.1",
+ :req_header => {:authorization => 'Bearer ' + token,
+ :content_type => 'application/json',
+ :app_key => app_id,
+ :platform => "Huawei oceanconnect"
+ }}
+ client_iot_mongo.audit_iot_logger(fff, url_string, "Get", out_resp)
+ out_resp
end
#2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
def querying_device_direct_conn(app_id, secret, dev_list)
output_str = {}
@@ -333,19 +374,21 @@
output_str = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
fff = {:func => "querying_device_direct_conn",
:iot_fun => "2.9.6",
:req_header => {:authorization => 'Bearer ' + token,
:content_type => 'application/json',
- :app_key => app_id
+ :app_key => app_id,
+ :platform => "Huawei oceanconnect"
}}
client_iot_mongo.audit_iot_logger(fff, url_string, req_body, output_str)
output_str
end
#2.9.19 Querying the Complete Device Type List of All Device Capabilities
def querying_device_type_list(app_id, secret)
+ output_ans = {}
token = get_token(app_id, secret)[:body]["accessToken"]
path = "/iocm/app/profile/v1.1.0/allDeviceTypes"
url_string = "https://" + platformip + ":" + platformport + path
uri = URI.parse url_string
https = Net::HTTP.new(uri.host, uri.port)
@@ -356,17 +399,28 @@
request = Net::HTTP::Get.new(uri.path)
request.content_type = 'application/json'
request['Authorization'] = 'Bearer ' + token
request['app_key'] = app_id
res = https.request(request)
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
+ output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
+
+ fff = {:func => "querying_device_type_list",
+ :iot_fun => "2.9.19",
+ :req_header => {:content_type => 'application/json',
+ :authorization => 'Bearer ' + token,
+ :app_key => app_id,
+ :platform => "Huawei oceanconnect"
+ }}
+ client_iot_mongo.audit_iot_logger(fff, url_string, "Get", output_ans)
+ output_ans
+
end
#2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
def quer_dev_direct_conn_batches(app_id, dev_list, token)
-
+ output_ans = {}
path = "/iocm/app/dm/v1.1.0/queryDevicesByIds"
url_string = "https://" + platformip + ":" + platformport + path
p url_string
uri = URI.parse url_string
https = Net::HTTP.new(uri.host, uri.port)
@@ -376,14 +430,23 @@
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(uri.path)
request.content_type = 'application/json'
request['Authorization'] = 'Bearer ' + token
request['app_key'] = app_id
- request.body = {deviceIds: dev_list}.to_json
+ data = {deviceIds: dev_list}
+ request.body = data.to_json
res = https.request(request)
- {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
-
+ output_ans = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
+ fff = {:func => "quer_dev_direct_conn_batches",
+ :iot_fun => "2.9.6",
+ :req_header => {:content_type => 'application/json',
+ :authorization => 'Bearer ' + token,
+ :app_key => app_id,
+ :platform => "Huawei oceanconnect"
+ }}
+ client_iot_mongo.audit_iot_logger(fff, url_string, data, output_ans)
+ output_ans
end
#2.2.11 Modifying Device Information (V2)
def dev_modify_location_v2(app_id, dev_id, token, address)
@@ -415,10 +478,11 @@
end
fff = {:func => "dev_modify_location_v2",
:iot_fun => "2.2.11",
:req_header => {:authorization => 'Bearer ' + token,
:content_type => 'application/json',
- :app_key => app_id
+ :app_key => app_id,
+ :platform => "Huawei oceanconnect"
}}
client_iot_mongo.audit_iot_logger(fff, url_string, req_b, out_resp)
rescue
out_resp = {:code => 500, :message => "dev_modify_location_v2: Unknown IOT error"}
end
\ No newline at end of file