lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb in imperituroard-0.5.9 vs lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb in imperituroard-1.0.0
- old
+ new
@@ -4,25 +4,27 @@
require 'json'
require 'rubygems'
require 'nokogiri'
require 'rails'
require "imperituroard/projects/iot/internal_functions"
+require 'imperituroard/projects/iot/mongoconnector'
class HuaIot
- attr_accessor :platformip, :platformport, :client, :database, :cert_file, :key_file, :internal_func
+ attr_accessor :platformip, :platformport, :client, :database, :cert_file, :key_file, :internal_func, :client_iot_mongo
- def initialize(platformip, platformport, cert_file, key_file)
+ def initialize(platformip, platformport, cert_file, key_file, mongo_ip, mongo_port, mongo_database)
@database = database
@platformip = platformip
@platformport = platformport
@cert_file = cert_file
@key_file = key_file
#client_host = [mongoip + ":" + mongoport]
#@client = Mongo::Client.new(client_host, :database => database)
@internal_func = InternalFunc.new
+ @client_iot_mongo = MongoIot.new(mongo_ip, mongo_port, mongo_database)
end
def parse_token(str)
begin
dd = str.split(",")
@@ -155,17 +157,22 @@
deviceType: device_type,
manufacturerId: manufacturer_id,
manufacturerName: manufacturer_name,
model: model,
isSecurity: "FALSE",
- supportedSecurity: "FALSE"}}.to_json
+ supportedSecurity: "FALSE"}}
internal_func.printer_texter({:procedure => "dev_register_passw_code_mode2", :data => {:body => data_out, :url => url_string}}, "debug")
- request.body = data_out
+ request.body = data_out.to_json
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_register_passw_code_mode2",
+ :iot_fun => "2.2.4",
+ :req_header => {:authorization => 'Bearer ' + token,
+ :content_type => 'application/json',
+ :app_key => app_id
+ }}
+ client_iot_mongo.audit_iot_logger(fff, url_string, data_out, out_resp)
out_resp
end
#2.2.4 Registering a Directly Connected Device (Password Mode) (V2)
@@ -219,10 +226,18 @@
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
+
+ fff = {:func => "dev_delete",
+ :iot_fun => "2.2.12",
+ :req_header => {:authorization => 'Bearer ' + token,
+ :content_type => 'application/json',
+ :app_key => app_id
+ }}
+ client_iot_mongo.audit_iot_logger(fff, url_string, "Delete", out_resp)
rescue
out_resp = {:code => 500, :message => "dev_delete: Unknown IOT error"}
end
p out_resp
out_resp
@@ -362,11 +377,11 @@
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")
+ 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))
@@ -388,10 +403,9 @@
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
\ No newline at end of file