lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb in imperituroard-0.3.2 vs lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb in imperituroard-0.3.3
- old
+ new
@@ -48,11 +48,11 @@
{:status => 500, :result => "failed"}
end
end
def get_token(app_id, secret)
- internal_func.printer_texter("get_token: start. Step1, iput: app_id: #{app_id.to_s}, #{secret.to_s}", "debug")
+ internal_func.printer_texter("get_token: start. Step1, iput: app_id: #{app_id.to_s}, secret: #{secret.to_s}", "debug")
out_resp = {}
begin
path = "/iocm/app/sec/v1.1.0/login"
url_string = "https://" + platformip + ":" + platformport + path
internal_func.printer_texter("get_token: start. Step2, url_string: #{url_string}", "debug")
@@ -132,11 +132,11 @@
p res.body.to_s
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
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)
+ 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 = {}
token = get_token(app_id, secret)[:body]["accessToken"]
path = "/iocm/app/reg/v2.0.0/deviceCredentials?appId=" + app_id
url_string = "https://" + platformip + ":" + platformport + path
uri = URI.parse url_string
@@ -147,19 +147,56 @@
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 = {deviceInfo: {nodeId: node_id, name: name_p, description: description_p, deviceType: device_type}}.to_json
+ data_out = {deviceInfo: {nodeId: node_id,
+ name: name_p,
+ description: description_p,
+ deviceType: device_type,
+ manufacturerId: manufacturer_id,
+ manufacturerName: manufacturer_name,
+ model: model,
+ isSecurity: "FALSE",
+ supportedSecurity: "FALSE"}}.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
out_resp
end
+ #2.2.4 Registering a Directly Connected Device (Password Mode) (V2)
+ def dev_reg_passw_code_mode2_2(app_id, secret, attr_list)
+ out_resp = {}
+ token = get_token(app_id, secret)[:body]["accessToken"]
+ path = "/iocm/app/reg/v2.0.0/deviceCredentials?appId=" + app_id
+ url_string = "https://" + platformip + ":" + platformport + path
+ uri = URI.parse url_string
+ https = Net::HTTP.new(uri.host, uri.port)
+ https.use_ssl = true
+ https.cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
+ https.key = OpenSSL::PKey::RSA.new(File.read(key_file))
+ 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
+ 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
+ out_resp
+ end
+
+
#2.2.12 Deleting a Directly Connected Device
def dev_delete(app_id, dev_id, token)
out_resp = {}
begin
@@ -186,11 +223,10 @@
rescue
out_resp = {:code => 500, :message => "dev_delete: Unknown IOT error"}
end
p out_resp
out_resp
-
end
#2.2.44 Querying the Device ID
def querying_device_id(app_id, secret, node_id)
@@ -296,13 +332,12 @@
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
end
#2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
- def quer_dev_direct_conn_batches(app_id, secret, dev_list)
- token = get_token(app_id, secret)[:body]["accessToken"]
- p token
+ def quer_dev_direct_conn_batches(app_id, dev_list, token)
+
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)
@@ -315,25 +350,94 @@
request['Authorization'] = 'Bearer ' + token
request['app_key'] = app_id
request.body = {deviceIds: dev_list}.to_json
res = https.request(request)
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
+
end
+ #2.2.11 Modifying Device Information (V2)
+ def dev_modify_location_v2(app_id, dev_id, token, address)
+ out_resp = {}
+
+ begin
+ path = "/iocm/app/dm/v1.4.0/devices/" + dev_id + "?app_Id=" + app_id
+ url_string = "https://" + platformip + ":" + platformport + path
+ internal_func.printer_texter({:url_string=>url_string, :procedure=>"dev_modify_location_v2"}, "debug")
+ uri = URI.parse url_string
+ https = Net::HTTP.new(uri.host, uri.port)
+ https.use_ssl = true
+ https.cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
+ https.key = OpenSSL::PKey::RSA.new(File.read(key_file))
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ request = Net::HTTP::Put.new(uri.path)
+ request.content_type = 'application/json'
+ request['Authorization'] = 'Bearer ' + token
+ request['app_key'] = app_id
+ request.body = {location: address}.to_json
+ res = https.request(request)
+ p res.code
+ p res.body
+ if res.body != nil
+ out_resp = {:code => res.code, :message => res.message, :body => {:answ => JSON.parse(res.body.to_s)}}
+ else
+ out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
+ end
+ rescue
+ out_resp = {:code => 500, :message => "dev_modify_location_v2: Unknown IOT error"}
+ end
+ p out_resp
+ out_resp
+ end
+
+
+
##2.10.7 Adding Members to a Device Group
##############################################################3
########final procedures###############
- def add_new_device_on_huawei(app_id, secret, node_id, name_p, description_p, device_type, profile)
- self.dev_register_passw_code_mode2(app_id, secret, node_id, name_p, description_p, device_type, profile)
+
+ def modify_location_iot(app_id, secret, dev_id, address)
+
+ out_resp = {}
+ begin
+ token = self.get_token(app_id, secret)
+ if token[:code] != 500 && token[:body]["accessToken"]!=nil
+ out_resp = self.dev_modify_location_v2(app_id, dev_id, token[:body]["accessToken"], address)
+ if out_resp[:code].to_i == 200 || out_resp[:code].to_i == 204
+ ###logout#
+ begin
+ self.token_logout(token[:body]["accessToken"])
+ rescue
+ nil
+ end
+ ##########
+ end
+ else
+ out_resp = {:code => 500, :message => "modify_location_iot: Invalid IOT platform token"}
+ end
+ rescue
+ out_resp = {:code => 500, :message => "modify_location_iot: Unknown error"}
+ end
+ jjj = {:procedure => "modify_location_iot", :answ => out_resp}
+ internal_func.printer_texter(jjj, "debug")
+ out_resp
end
+ def add_new_device_on_huawei(app_id, secret, node_id, name_p, description_p, device_type, profile, manufacturer_id, manufacturer_name, model)
+ self.dev_register_passw_code_mode2(app_id, secret, node_id, name_p, description_p, device_type, profile, manufacturer_id, manufacturer_name, model)
+ end
+ def add_new_device_on_huawei2(app_id, secret, attr_list)
+ self.dev_reg_passw_code_mode2_2(app_id, secret, attr_list)
+ end
+
+
def remove_one_device_from_iot(app_id, secret, dev_id)
out_resp = {}
begin
token = self.get_token(app_id, secret)
if token[:code] != 500 && token[:body]["accessToken"]!=nil
@@ -351,10 +455,37 @@
out_resp = {:code => 500, :message => "remove_one_device_from_iot: Invalid IOT platform token"}
end
rescue
out_resp = {:code => 500, :message => "remove_one_device_from_iot: Unknown error"}
end
- p jjj = {:procedure => "remove_one_device_from_iot", :answ => out_resp}
+ jjj = {:procedure => "remove_one_device_from_iot", :answ => out_resp}
+ internal_func.printer_texter(jjj, "debug")
+ out_resp
+ end
+
+ def quer_dev_query_list(app_id, secret, dev_list)
+ out_resp = {}
+ begin
+ token = self.get_token(app_id, secret)
+ if token[:code] != 500 && token[:body]["accessToken"]!=nil
+ out_resp = self.quer_dev_direct_conn_batches(app_id, dev_list, token[:body]["accessToken"])
+ if out_resp[:code].to_i == 200 || out_resp[:code].to_i == 204
+ ###logout#
+ begin
+ self.token_logout(token[:body]["accessToken"])
+ rescue
+ nil
+ end
+ ##########
+ end
+ else
+ out_resp = {:code => 500, :message => "quer_dev_query_list: Invalid IOT platform token"}
+ end
+ rescue
+ out_resp = {:code => 500, :message => "quer_dev_query_list: Unknown error"}
+ end
+ jjj = {:procedure => "quer_dev_query_list", :answ => out_resp}
+ internal_func.printer_texter(jjj, "debug")
out_resp
end
#######################################
\ No newline at end of file