lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb in imperituroard-0.2.5 vs lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb in imperituroard-0.2.7
- old
+ new
@@ -9,15 +9,14 @@
class HuaIot
attr_accessor :platformip, :platformport, :client, :database, :cert_file, :key_file
- def initialize(platformip, platformport, iotip, database, cert_file, key_file)
+ def initialize(platformip, platformport, cert_file, key_file)
@database = database
@platformip = platformip
@platformport = platformport
- @iotip = iotip
@cert_file = cert_file
@key_file = key_file
#client_host = [mongoip + ":" + mongoport]
#@client = Mongo::Client.new(client_host, :database => database)
end
@@ -87,14 +86,37 @@
res = https.request(request)
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)
+ 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
+ request.body = {deviceInfo: {nodeId: node_id, name: name_p, description: description_p, deviceType: device_type}}.to_json
+ res = https.request(request)
+ p res.body.to_s
+ {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
+ end
- def dev_delete(app_id, secret, node_id)
+
+
+ #2.2.12 Deleting a Directly Connected Device
+ def dev_delete(app_id, secret, dev_id)
token = get_token(app_id, secret)[:body]["accessToken"]
- path = "/iocm/app/dm/v1.1.0/devices/" + node_id + "?app_Id=" + app_id + "&cascade=true"
+ path = "/iocm/app/dm/v1.1.0/devices/" + dev_id + "?app_Id=" + app_id + "&cascade=true"
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))
@@ -103,17 +125,25 @@
request = Net::HTTP::Delete.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)}
+ p res.code
+ p res.body
+ if res.body != nil
+ {:code => res.code, :message => res.message, :body => {:answ => JSON.parse(res.body.to_s)}}
+ else
+ {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
+ end
+
end
#2.2.44 Querying the Device ID
def querying_device_id(app_id, secret, node_id)
token = get_token(app_id, secret)[:body]["accessToken"]
+ p token
path = "/iocm/app/dm/v1.1.0/queryDeviceIdByNodeId?nodeId=" + node_id
p path
p path
url_string = "https://" + platformip + ":" + platformport + path
p url_string
@@ -125,13 +155,13 @@
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.path)
request.content_type = 'application/json'
request['Authorization'] = 'Bearer ' + token
request['app_key'] = app_id
- p request.body
res = https.request(request)
p res.body.to_s
+ p res.code
{: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)
@@ -214,12 +244,14 @@
#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
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)
https.use_ssl = true
https.cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
https.key = OpenSSL::PKey::RSA.new(File.read(key_file))
@@ -232,9 +264,28 @@
res = https.request(request)
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
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)
+ dev_register_passw_code_mode2(app_id, secret, node_id, name_p, description_p, device_type, profile)
+ end
+
+
+ def remove_one_device_from_iot(app_id, secret, dev_id)
+ dev_delete(app_id, secret, dev_id)
+ end
+
+
+ #######################################
def test()
url_string = "https://134.17.93.4:8743/iocm/app/sec/v1.1.0/login"
headers = {
\ No newline at end of file