lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb in imperituroard-1.1.8 vs lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb in imperituroard-1.1.9
- old
+ new
@@ -80,10 +80,11 @@
}
internal_func.printer_texter("get_token: start. Step3, data: #{data.to_s}", "debug")
request.content_type = 'application/x-www-form-urlencoded'
request.body = URI.encode_www_form(data)
res = https.request(request)
+ p "get_token"
p res.code
p res.message
p res.body.to_s
out_resp = {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
@@ -291,33 +292,33 @@
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 + "&appId=Jy5KpoBUOScZEcrO2bRZhzfaIOUa"
- p path
- p path
- 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))
- 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
- #request['node-id'] = node_id
- bbb = {"nodeId": node_id, "appId": "Jy5KpoBUOScZEcrO2bRZhzfaIOUa"}.to_json
- request.body = bbb
- res = https.request(request)
- p res.body.to_s
- p res.code
- {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
+ get_token_data = get_token(app_id, secret)
+ if get_token_data[:code]=="200"
+ token = get_token_data[:body]["accessToken"]
+ uri1 = URI("https://134.17.93.4:8743/iocm/app/dm/v1.1.0/queryDeviceIdByNodeId?nodeId=" + node_id + "&" + app_id)
+ https = Net::HTTP.new(uri1.host, uri1.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::Get.new(uri1)
+ request.content_type = 'application/json'
+ request['app_key'] = app_id
+ request['Authorization'] = 'Bearer ' + token
+ #request.set_form_data( params )
+ #request['node-id'] = node_id
+ bbb = {"nodeId": node_id, "appId": "Jy5KpoBUOScZEcrO2bRZhzfaIOUa"}.to_json
+ #request.body = bbb
+ res = https.request(request)
+ #p res.body.to_s
+ #p res.code
+ {:code => res.code, :message => res.message, :body => valid_json?(res.body.to_s)}
+ else
+ {:code => "500", :message => "Something wrong", :body => {}}
+ end
end
#2.2.14 Querying Device Activation Status
def querying_device_activ_status(app_id, secret, device_id)
output_ans = {}
\ No newline at end of file