imperituroard 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/imperituroard/projects/iot/hua_oceanconnect_adapter.rb +141 -10
- data/lib/imperituroard/projects/iot/internal_functions.rb +3 -1
- data/lib/imperituroard/projects/iot/mongoconnector.rb +38 -5
- data/lib/imperituroard/version.rb +1 -1
- data/lib/imperituroard.rb +160 -64
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9145a7e26b0478b84af6d549588cd403cf52080d
|
4
|
+
data.tar.gz: fbdc0528f7ff7e535eaa29a2ad3eba67216163be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2db737b82e9d6127b475ea6c6e472d86c82857a253fb8e16e5de2c804fdded8681a4764d1c6735994c783e81da413370d95b300a498094fc98276792a623544e
|
7
|
+
data.tar.gz: 8e93980bda5a7d66317611c4291c62b4f094d318dd45f404196f7c5219c6fec88ae2637f00f59f0c5cc62747a56543a67d355b977209ba68ab80352b2b853e83
|
@@ -50,7 +50,7 @@ class HuaIot
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def get_token(app_id, secret)
|
53
|
-
internal_func.printer_texter("get_token: start. Step1, iput: app_id: #{app_id.to_s}, #{secret.to_s}", "debug")
|
53
|
+
internal_func.printer_texter("get_token: start. Step1, iput: app_id: #{app_id.to_s}, secret: #{secret.to_s}", "debug")
|
54
54
|
out_resp = {}
|
55
55
|
begin
|
56
56
|
path = "/iocm/app/sec/v1.1.0/login"
|
@@ -134,7 +134,7 @@ class HuaIot
|
|
134
134
|
end
|
135
135
|
|
136
136
|
#2.2.4 Registering a Directly Connected Device (Password Mode) (V2)
|
137
|
-
def dev_register_passw_code_mode2(app_id, secret, node_id, name_p, description_p, device_type, profile)
|
137
|
+
def dev_register_passw_code_mode2(app_id, secret, node_id, name_p, description_p, device_type, profile, manufacturer_id, manufacturer_name, model)
|
138
138
|
out_resp = {}
|
139
139
|
token = get_token(app_id, secret)[:body]["accessToken"]
|
140
140
|
path = "/iocm/app/reg/v2.0.0/deviceCredentials?appId=" + app_id
|
@@ -149,7 +149,44 @@ class HuaIot
|
|
149
149
|
request.content_type = 'application/json'
|
150
150
|
request['Authorization'] = 'Bearer ' + token
|
151
151
|
request['app_key'] = app_id
|
152
|
-
|
152
|
+
data_out = {deviceInfo: {nodeId: node_id,
|
153
|
+
name: name_p,
|
154
|
+
description: description_p,
|
155
|
+
deviceType: device_type,
|
156
|
+
manufacturerId: manufacturer_id,
|
157
|
+
manufacturerName: manufacturer_name,
|
158
|
+
model: model,
|
159
|
+
isSecurity: "FALSE",
|
160
|
+
supportedSecurity: "FALSE"}}.to_json
|
161
|
+
internal_func.printer_texter({:procedure => "dev_register_passw_code_mode2", :data => {:body => data_out, :url => url_string}}, "debug")
|
162
|
+
request.body = data_out
|
163
|
+
res = https.request(request)
|
164
|
+
p res.body.to_s
|
165
|
+
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
166
|
+
p out_resp
|
167
|
+
out_resp
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
#2.2.4 Registering a Directly Connected Device (Password Mode) (V2)
|
172
|
+
def dev_reg_passw_code_mode2_2(app_id, secret, attr_list)
|
173
|
+
out_resp = {}
|
174
|
+
token = get_token(app_id, secret)[:body]["accessToken"]
|
175
|
+
path = "/iocm/app/reg/v2.0.0/deviceCredentials?appId=" + app_id
|
176
|
+
url_string = "https://" + platformip + ":" + platformport + path
|
177
|
+
uri = URI.parse url_string
|
178
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
179
|
+
https.use_ssl = true
|
180
|
+
https.cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
|
181
|
+
https.key = OpenSSL::PKey::RSA.new(File.read(key_file))
|
182
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
183
|
+
request = Net::HTTP::Post.new(uri.path)
|
184
|
+
request.content_type = 'application/json'
|
185
|
+
request['Authorization'] = 'Bearer ' + token
|
186
|
+
request['app_key'] = app_id
|
187
|
+
data_out = {deviceInfo: attr_list}.to_json
|
188
|
+
internal_func.printer_texter({:procedure => "dev_register_passw_code_mode2", :data => {:body => data_out, :url => url_string}}, "debug")
|
189
|
+
request.body = data_out
|
153
190
|
res = https.request(request)
|
154
191
|
p res.body.to_s
|
155
192
|
out_resp = {:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
@@ -188,7 +225,6 @@ class HuaIot
|
|
188
225
|
end
|
189
226
|
p out_resp
|
190
227
|
out_resp
|
191
|
-
|
192
228
|
end
|
193
229
|
|
194
230
|
|
@@ -298,9 +334,8 @@ class HuaIot
|
|
298
334
|
|
299
335
|
|
300
336
|
#2.9.6 Querying Directly Connected Devices and Their Mounted Devices in Batches
|
301
|
-
def quer_dev_direct_conn_batches(app_id,
|
302
|
-
|
303
|
-
p token
|
337
|
+
def quer_dev_direct_conn_batches(app_id, dev_list, token)
|
338
|
+
|
304
339
|
path = "/iocm/app/dm/v1.1.0/queryDevicesByIds"
|
305
340
|
url_string = "https://" + platformip + ":" + platformport + path
|
306
341
|
p url_string
|
@@ -317,9 +352,46 @@ class HuaIot
|
|
317
352
|
request.body = {deviceIds: dev_list}.to_json
|
318
353
|
res = https.request(request)
|
319
354
|
{:code => res.code, :message => res.message, :body => JSON.parse(res.body.to_s)}
|
355
|
+
|
356
|
+
end
|
357
|
+
|
358
|
+
|
359
|
+
#2.2.11 Modifying Device Information (V2)
|
360
|
+
def dev_modify_location_v2(app_id, dev_id, token, address)
|
361
|
+
out_resp = {}
|
362
|
+
|
363
|
+
begin
|
364
|
+
path = "/iocm/app/dm/v1.4.0/devices/" + dev_id + "?app_Id=" + app_id
|
365
|
+
url_string = "https://" + platformip + ":" + platformport + path
|
366
|
+
internal_func.printer_texter({:url_string=>url_string, :procedure=>"dev_modify_location_v2"}, "debug")
|
367
|
+
uri = URI.parse url_string
|
368
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
369
|
+
https.use_ssl = true
|
370
|
+
https.cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
|
371
|
+
https.key = OpenSSL::PKey::RSA.new(File.read(key_file))
|
372
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
373
|
+
request = Net::HTTP::Put.new(uri.path)
|
374
|
+
request.content_type = 'application/json'
|
375
|
+
request['Authorization'] = 'Bearer ' + token
|
376
|
+
request['app_key'] = app_id
|
377
|
+
request.body = {location: address}.to_json
|
378
|
+
res = https.request(request)
|
379
|
+
p res.code
|
380
|
+
p res.body
|
381
|
+
if res.body != nil
|
382
|
+
out_resp = {:code => res.code, :message => res.message, :body => {:answ => JSON.parse(res.body.to_s)}}
|
383
|
+
else
|
384
|
+
out_resp = {:code => res.code, :message => res.message, :body => {:answ => "no data"}}
|
385
|
+
end
|
386
|
+
rescue
|
387
|
+
out_resp = {:code => 500, :message => "dev_modify_location_v2: Unknown IOT error"}
|
388
|
+
end
|
389
|
+
p out_resp
|
390
|
+
out_resp
|
320
391
|
end
|
321
392
|
|
322
393
|
|
394
|
+
|
323
395
|
##2.10.7 Adding Members to a Device Group
|
324
396
|
|
325
397
|
|
@@ -327,8 +399,40 @@ class HuaIot
|
|
327
399
|
|
328
400
|
|
329
401
|
########final procedures###############
|
330
|
-
|
331
|
-
|
402
|
+
|
403
|
+
def modify_location_iot(app_id, secret, dev_id, address)
|
404
|
+
|
405
|
+
out_resp = {}
|
406
|
+
begin
|
407
|
+
token = self.get_token(app_id, secret)
|
408
|
+
if token[:code] != 500 && token[:body]["accessToken"]!=nil
|
409
|
+
out_resp = self.dev_modify_location_v2(app_id, dev_id, token[:body]["accessToken"], address)
|
410
|
+
if out_resp[:code].to_i == 200 || out_resp[:code].to_i == 204
|
411
|
+
###logout#
|
412
|
+
begin
|
413
|
+
self.token_logout(token[:body]["accessToken"])
|
414
|
+
rescue
|
415
|
+
nil
|
416
|
+
end
|
417
|
+
##########
|
418
|
+
end
|
419
|
+
else
|
420
|
+
out_resp = {:code => 500, :message => "modify_location_iot: Invalid IOT platform token"}
|
421
|
+
end
|
422
|
+
rescue
|
423
|
+
out_resp = {:code => 500, :message => "modify_location_iot: Unknown error"}
|
424
|
+
end
|
425
|
+
jjj = {:procedure => "modify_location_iot", :answ => out_resp}
|
426
|
+
internal_func.printer_texter(jjj, "debug")
|
427
|
+
out_resp
|
428
|
+
end
|
429
|
+
|
430
|
+
def add_new_device_on_huawei(app_id, secret, node_id, name_p, description_p, device_type, profile, manufacturer_id, manufacturer_name, model)
|
431
|
+
self.dev_register_passw_code_mode2(app_id, secret, node_id, name_p, description_p, device_type, profile, manufacturer_id, manufacturer_name, model)
|
432
|
+
end
|
433
|
+
|
434
|
+
def add_new_device_on_huawei2(app_id, secret, attr_list)
|
435
|
+
self.dev_reg_passw_code_mode2_2(app_id, secret, attr_list)
|
332
436
|
end
|
333
437
|
|
334
438
|
|
@@ -353,7 +457,34 @@ class HuaIot
|
|
353
457
|
rescue
|
354
458
|
out_resp = {:code => 500, :message => "remove_one_device_from_iot: Unknown error"}
|
355
459
|
end
|
356
|
-
|
460
|
+
jjj = {:procedure => "remove_one_device_from_iot", :answ => out_resp}
|
461
|
+
internal_func.printer_texter(jjj, "debug")
|
462
|
+
out_resp
|
463
|
+
end
|
464
|
+
|
465
|
+
def quer_dev_query_list(app_id, secret, dev_list)
|
466
|
+
out_resp = {}
|
467
|
+
begin
|
468
|
+
token = self.get_token(app_id, secret)
|
469
|
+
if token[:code] != 500 && token[:body]["accessToken"]!=nil
|
470
|
+
out_resp = self.quer_dev_direct_conn_batches(app_id, dev_list, token[:body]["accessToken"])
|
471
|
+
if out_resp[:code].to_i == 200 || out_resp[:code].to_i == 204
|
472
|
+
###logout#
|
473
|
+
begin
|
474
|
+
self.token_logout(token[:body]["accessToken"])
|
475
|
+
rescue
|
476
|
+
nil
|
477
|
+
end
|
478
|
+
##########
|
479
|
+
end
|
480
|
+
else
|
481
|
+
out_resp = {:code => 500, :message => "quer_dev_query_list: Invalid IOT platform token"}
|
482
|
+
end
|
483
|
+
rescue
|
484
|
+
out_resp = {:code => 500, :message => "quer_dev_query_list: Unknown error"}
|
485
|
+
end
|
486
|
+
jjj = {:procedure => "quer_dev_query_list", :answ => out_resp}
|
487
|
+
internal_func.printer_texter(jjj, "debug")
|
357
488
|
out_resp
|
358
489
|
end
|
359
490
|
|
@@ -1,10 +1,12 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path("../projects/iot", __dir__)
|
2
2
|
|
3
|
+
require 'date'
|
4
|
+
|
3
5
|
class InternalFunc
|
4
6
|
|
5
7
|
|
6
8
|
def printer_texter(text, log_level)
|
7
|
-
mess = {:sdk=> "imperituroard", :sdk_version=> "0.3.
|
9
|
+
mess = {:datetime => DateTime.now, :sdk=> "imperituroard", :sdk_version=> "0.3.3", :message => text}
|
8
10
|
p mess
|
9
11
|
end
|
10
12
|
|
@@ -23,8 +23,7 @@ class MongoIot
|
|
23
23
|
def audit_logger(proc_name, src_ip, input_json, output_json, real_ip)
|
24
24
|
out_resp = {}
|
25
25
|
begin
|
26
|
-
|
27
|
-
current = d.strftime("%d/%m/%Y %H:%M:%S")
|
26
|
+
current = DateTime.now
|
28
27
|
collection = client[:audit]
|
29
28
|
doc = {
|
30
29
|
:proc_name => proc_name,
|
@@ -213,7 +212,7 @@ class MongoIot
|
|
213
212
|
p not_ex
|
214
213
|
p res_exists
|
215
214
|
out_resp = {:code => 200, :result => "check_imei_exists: Request completed successfully",
|
216
|
-
|
215
|
+
:body => {:exists => res_exists, :not_exists => not_ex}}
|
217
216
|
internal_func.printer_texter(out_resp, "debug")
|
218
217
|
out_resp
|
219
218
|
end
|
@@ -238,7 +237,7 @@ class MongoIot
|
|
238
237
|
p result
|
239
238
|
end
|
240
239
|
rescue
|
241
|
-
|
240
|
+
nil
|
242
241
|
end
|
243
242
|
end
|
244
243
|
|
@@ -262,10 +261,22 @@ class MongoIot
|
|
262
261
|
p result
|
263
262
|
end
|
264
263
|
rescue
|
265
|
-
|
264
|
+
nil
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
|
269
|
+
def imei_insert_model(model)
|
270
|
+
begin
|
271
|
+
collection = client[:device_types]
|
272
|
+
result = collection.insert_one(model)
|
273
|
+
p result
|
274
|
+
rescue
|
275
|
+
nil
|
266
276
|
end
|
267
277
|
end
|
268
278
|
|
279
|
+
|
269
280
|
def get_profile_name_from_imei(imei)
|
270
281
|
out_resp = {}
|
271
282
|
begin
|
@@ -386,6 +397,28 @@ class MongoIot
|
|
386
397
|
end
|
387
398
|
|
388
399
|
|
400
|
+
def get_device_type_info_by_model(device_model)
|
401
|
+
out_resp = {}
|
402
|
+
begin
|
403
|
+
result_ps = []
|
404
|
+
collection = client[:device_types]
|
405
|
+
collection.find({"model" => device_model}).each {|row|
|
406
|
+
result_ps.append(row)
|
407
|
+
}
|
408
|
+
dattaa = result_ps[0]
|
409
|
+
if dattaa!=nil
|
410
|
+
out_resp = {:code => 200, :result => "get_device_type_info_by_model: Request completed successfully", :body => dattaa}
|
411
|
+
else
|
412
|
+
out_resp = {:code => 404, :result => "get_device_type_info_by_model: Device info not found", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
|
413
|
+
end
|
414
|
+
rescue
|
415
|
+
out_resp = {:code => 500, :result => "get_device_type_info_by_model: procedure error", :body => {"model" => device_model, "ManufacturerID" => "unknown", "ManufacturerNAME" => "unknown", "device_type" => "unknown"}}
|
416
|
+
end
|
417
|
+
internal_func.printer_texter(out_resp, "debug")
|
418
|
+
out_resp
|
419
|
+
end
|
420
|
+
|
421
|
+
|
389
422
|
def ttt
|
390
423
|
p "111111"
|
391
424
|
begin
|
data/lib/imperituroard.rb
CHANGED
@@ -10,6 +10,7 @@ require "imperituroard/projects/iot/add_functions"
|
|
10
10
|
require "imperituroard/projects/iot/internal_functions"
|
11
11
|
require 'json'
|
12
12
|
require 'ipaddr'
|
13
|
+
require 'date'
|
13
14
|
|
14
15
|
module Imperituroard
|
15
16
|
class Error < StandardError;
|
@@ -98,7 +99,8 @@ class Iot
|
|
98
99
|
:add_functions_connector,
|
99
100
|
:real_ip, #real ip address of procedure caller
|
100
101
|
:remote_ip, #ip address of balancer
|
101
|
-
:hua_aceanconnect_connector
|
102
|
+
:hua_aceanconnect_connector,
|
103
|
+
:internal_func
|
102
104
|
|
103
105
|
def initialize(mongoip, mongoport, iotip, mongo_database,
|
104
106
|
iotplatform_ip, iotplatform_port, cert_path, key_path, telegram_api_url, telegram_chat_id, real_ip, remote_ip)
|
@@ -115,6 +117,7 @@ class Iot
|
|
115
117
|
@real_ip = real_ip
|
116
118
|
@remote_ip = remote_ip
|
117
119
|
@hua_aceanconnect_connector = HuaIot.new(iotplatform_ip, iotplatform_port, cert_path, key_path)
|
120
|
+
@internal_func = InternalFunc.new
|
118
121
|
end
|
119
122
|
|
120
123
|
#error list
|
@@ -177,10 +180,25 @@ class Iot
|
|
177
180
|
for aaa in for_insert
|
178
181
|
begin
|
179
182
|
dev_name = aaa["imei"].to_s
|
180
|
-
|
183
|
+
|
184
|
+
#get {"model"=>"BGT_PPMC", "ManufacturerID"=>"unknown", "ManufacturerNAME"=>"unknown", "device_type"=>"unknown"}
|
185
|
+
#from database
|
186
|
+
model_data = mongo_client.get_device_type_info_by_model(aaa["device_type"])
|
187
|
+
resss = hua_aceanconnect_connector.add_new_device_on_huawei(credentials[:body][:app_id],
|
188
|
+
credentials[:body][:secret],
|
189
|
+
aaa["imei"],
|
190
|
+
dev_name,
|
191
|
+
aaa["description"],
|
192
|
+
model_data[:body]["device_type"],
|
193
|
+
aaa["profile"],
|
194
|
+
model_data[:body]["ManufacturerID"],
|
195
|
+
model_data[:body]["ManufacturerNAME"],
|
196
|
+
model_data[:body]["model"]
|
197
|
+
)
|
181
198
|
if resss[:code]=="200"
|
182
199
|
s1 = aaa
|
183
200
|
s1[:huadata] = resss
|
201
|
+
s1[:created] = DateTime.now
|
184
202
|
added_on_iot_platf.append(s1)
|
185
203
|
else
|
186
204
|
not_processed_list.append({:imei => aaa["imei"], :error => resss})
|
@@ -282,15 +300,29 @@ class Iot
|
|
282
300
|
|
283
301
|
li_new_imei = []
|
284
302
|
list1 = {}
|
303
|
+
|
304
|
+
#dictionary for imeis which not processed. Final dictionary
|
285
305
|
not_processed_list = []
|
306
|
+
|
307
|
+
#dictionary for devices which was processed correctly
|
308
|
+
processed_list = []
|
309
|
+
|
310
|
+
#array for translations from old imei to new
|
311
|
+
old_new_translation = {}
|
312
|
+
|
286
313
|
approved_list = []
|
287
314
|
resp_out = {}
|
288
315
|
|
316
|
+
#old_imei_list for query to iot platform for data request
|
317
|
+
step1_approved_dict_old=[]
|
318
|
+
|
319
|
+
#form dictionary for processing
|
289
320
|
for pr1 in im_list
|
290
321
|
p "pr1"
|
291
322
|
p pr1
|
292
323
|
li_new_imei.append(pr1["imei_new"])
|
293
324
|
list1[pr1["imei_new"]]=pr1["imei_old"]
|
325
|
+
old_new_translation[pr1["imei_old"]]=pr1["imei_new"]
|
294
326
|
end
|
295
327
|
|
296
328
|
p list1
|
@@ -299,41 +331,37 @@ class Iot
|
|
299
331
|
|
300
332
|
thr3 = Thread.new do
|
301
333
|
|
334
|
+
#check if imei_new exists in database. If exists - not process this imei
|
302
335
|
list_checked = mongo_client.check_imei_exists(li_new_imei)
|
336
|
+
|
337
|
+
internal_func.printer_texter({:function => "imei_replace Step1", :list_checked => list_checked}, "debug")
|
338
|
+
|
339
|
+
#add already exists new IMEI in error dictionary
|
303
340
|
for ss in list_checked[:body][:exists]
|
304
341
|
not_processed_list.append({:record => {:imei_old => list1[ss], :imei_new => ss}, :error => "New IMEI exists in database"})
|
305
342
|
end
|
306
343
|
|
344
|
+
#new_imei list which processed step1
|
307
345
|
step2_list = list_checked[:body][:not_exists]
|
308
346
|
|
347
|
+
internal_func.printer_texter({:function => "imei_replace Step2", :step2_list => step2_list}, "debug")
|
348
|
+
|
349
|
+
|
309
350
|
for a in step2_list
|
310
351
|
begin
|
311
|
-
p "list1[a]"
|
312
|
-
p list1
|
313
|
-
p a
|
314
|
-
p list1[a]
|
315
|
-
prof_name1 = mongo_client.get_profile_name_from_imei(list1[a])
|
316
352
|
|
317
|
-
|
318
|
-
|
353
|
+
#step3 checking permission for writing for imei list
|
354
|
+
prof_name1 = mongo_client.get_profile_name_from_imei(list1[a])
|
319
355
|
|
320
|
-
|
356
|
+
internal_func.printer_texter({:function => "imei_replace Step3", :prof_name1 => prof_name1}, "debug")
|
321
357
|
|
358
|
+
if prof_name1[:code]==200
|
322
359
|
permiss1 = mongo_client.check_login_profile_permiss(login, prof_name1[:body]["profile"])[:code]
|
323
|
-
|
324
|
-
p permiss1
|
360
|
+
internal_func.printer_texter({:function => "imei_replace Step4", :permiss1 => permiss1, :input => prof_name1[:body]["profile"]}, "debug")
|
325
361
|
if permiss1==200
|
326
362
|
|
327
|
-
##Logic for IOT Platform connection###
|
328
|
-
|
329
|
-
remove_one_device_from_iot(app_id, secret, dev_id)
|
330
|
-
|
331
|
-
#########end iot platform logic#######
|
332
|
-
|
333
|
-
mongo_client.device_modify_any_attr_mongo(list1[a], {:imei => a})
|
334
|
-
|
335
363
|
approved_list.append({:imei_old => list1[a], :imei_new => a})
|
336
|
-
|
364
|
+
step1_approved_dict_old.append(list1[a])
|
337
365
|
|
338
366
|
else
|
339
367
|
not_processed_list.append({:record => {:imei_old => list1[a], :imei_new => a}, :error => "Old IMEI modification denied"})
|
@@ -346,15 +374,67 @@ class Iot
|
|
346
374
|
end
|
347
375
|
end
|
348
376
|
|
377
|
+
internal_func.printer_texter({:function => "imei_replace Step5", :not_processed_list => not_processed_list, :input => list1, :approved_list => approved_list, :step1_approved_dict_old => step1_approved_dict_old}, "debug")
|
378
|
+
|
379
|
+
|
380
|
+
##Logic for IOT Platform connection###
|
381
|
+
|
382
|
+
list_from_iot = self.get_info_by_imeilist_from_iot(login, step1_approved_dict_old)
|
383
|
+
|
384
|
+
internal_func.printer_texter({:function => "imei_replace Step6", :list_from_iot => list_from_iot, :description => "data from iot platform by old imei"}, "debug")
|
385
|
+
|
386
|
+
#processing data. modifying data on iot platform and mongoDB
|
387
|
+
if list_from_iot[:code]=="200"
|
388
|
+
|
389
|
+
for ard in list_from_iot[:body]["devices"]
|
390
|
+
p ard
|
391
|
+
new_data_cur_dev = {}
|
392
|
+
mongo_answer = {}
|
393
|
+
current_old_dev = ard["deviceInfo"]["nodeId"]
|
394
|
+
current_device_id = ard["deviceId"]
|
395
|
+
new_data_cur_dev = ard["deviceInfo"]
|
396
|
+
new_data_cur_dev["nodeId"] = old_new_translation[current_old_dev.to_i].to_s
|
397
|
+
|
398
|
+
credentials = mongo_client.get_iot_oceanconnect_credent(login)
|
399
|
+
|
400
|
+
if credentials[:code]==200
|
401
|
+
flag_remove=0
|
402
|
+
flag_create=0
|
403
|
+
remove_answer = hua_aceanconnect_connector.remove_one_device_from_iot(credentials[:body][:app_id], credentials[:body][:secret], current_device_id)
|
404
|
+
create_answer = hua_aceanconnect_connector.add_new_device_on_huawei2(credentials[:body][:app_id], credentials[:body][:secret], new_data_cur_dev)
|
405
|
+
|
406
|
+
if remove_answer[:code]=="204" || remove_answer[:code]=="200"
|
407
|
+
flag_remove=1
|
408
|
+
end
|
409
|
+
if create_answer[:code]=="200"
|
410
|
+
flag_create=1
|
411
|
+
end
|
412
|
+
if flag_remove==1 && flag_create==1
|
413
|
+
mongo_answer = mongo_client.device_modify_any_attr_mongo(current_old_dev.to_i, {:imei => old_new_translation[current_old_dev.to_i], :huadata => {:body => create_answer[:body]}, :updated => DateTime.now})
|
414
|
+
processed_list.append({:imei_old => current_old_dev.to_i, :imei_new => old_new_translation[current_old_dev.to_i]})
|
415
|
+
else
|
416
|
+
not_processed_list.append({:record => {:imei_old => current_old_dev.to_i, :imei_new => old_new_translation[current_old_dev.to_i]}, :error => "Failed for provisioning to IOT platform"})
|
417
|
+
end
|
418
|
+
|
419
|
+
internal_func.printer_texter({:function => "imei_replace Step7", :remove_answer => remove_answer, :create_answer => create_answer, :mongo_answer => mongo_answer, :description => "processing imei #{current_old_dev.to_s}"}, "debug")
|
420
|
+
|
421
|
+
else
|
422
|
+
approved_list=[]
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
else
|
427
|
+
approved_list=[]
|
428
|
+
end
|
429
|
+
|
349
430
|
if approved_list!=[]
|
350
|
-
resp_out = {:code => 200, :result => "Request completed successfully", :data => {:approved_list =>
|
431
|
+
resp_out = {:code => 200, :result => "Request completed successfully", :data => {:approved_list => processed_list, :unapproved_list => not_processed_list}}
|
351
432
|
else
|
352
|
-
resp_out = {:code => 202, :result => "Nothing to do", :data => {:approved_list =>
|
433
|
+
resp_out = {:code => 202, :result => "Nothing to do", :data => {:approved_list => processed_list, :unapproved_list => not_processed_list}}
|
353
434
|
end
|
354
435
|
|
355
436
|
end
|
356
437
|
|
357
|
-
|
358
438
|
rescue
|
359
439
|
resp_out = {:code => 507, :result => "Unknown SDK error"}
|
360
440
|
end
|
@@ -442,7 +522,8 @@ class Iot
|
|
442
522
|
#imei = newdevice_list
|
443
523
|
#address = newdevice_list
|
444
524
|
#newdevice_list=[{:imei=>7967843245665, :address=>"Golubeva51"}]
|
445
|
-
|
525
|
+
#+++
|
526
|
+
#iot platform integration completed
|
446
527
|
def device_add_address(login, newdevice_list)
|
447
528
|
#add_functions_connector.telegram_message(newdevice_list.to_s)
|
448
529
|
p newdevice_list
|
@@ -465,6 +546,21 @@ class Iot
|
|
465
546
|
if permiss[:code]==200
|
466
547
|
|
467
548
|
##Logic for IOT Platform connection###
|
549
|
+
credentials = mongo_client.get_iot_oceanconnect_credent(login)
|
550
|
+
resp = {}
|
551
|
+
|
552
|
+
if credentials[:code]==200
|
553
|
+
imei_data = mongo_client.get_imei_info_from_db([p[:imei]])
|
554
|
+
if imei_data[:body]!=[]
|
555
|
+
ans =hua_aceanconnect_connector.modify_location_iot(credentials[:body][:app_id], credentials[:body][:secret], imei_data[:body][0]["huadata"]["body"]["deviceId"], p[:address])
|
556
|
+
|
557
|
+
internal_func.printer_texter({:function => "device_add_address Step2", :ans => ans, :descrition=>"answer from hua IOT", :input=>{:did=>imei_data[:body][0]["huadata"]["body"]["deviceId"], :appid=>credentials[:body][:app_id], :secret=>credentials[:body][:secret], :address=>p[:address]}}, "debug")
|
558
|
+
|
559
|
+
p ans
|
560
|
+
end
|
561
|
+
|
562
|
+
end
|
563
|
+
|
468
564
|
|
469
565
|
#########end iot platform logic#######
|
470
566
|
|
@@ -542,11 +638,8 @@ class Iot
|
|
542
638
|
end
|
543
639
|
end
|
544
640
|
p attr
|
545
|
-
|
546
641
|
mongo_client.device_modify_any_attr_mongo(g["imei"], attr)
|
547
|
-
|
548
642
|
processed.append(g["imei"])
|
549
|
-
|
550
643
|
else
|
551
644
|
not_processed.append({:imei => g["imei"], :description => "New profile permission error", :error => permiss2})
|
552
645
|
end
|
@@ -554,9 +647,7 @@ class Iot
|
|
554
647
|
else
|
555
648
|
attr = g["attributes"]
|
556
649
|
mongo_client.device_modify_any_attr_mongo(g["imei"], attr)
|
557
|
-
|
558
650
|
processed.append(g["imei"])
|
559
|
-
|
560
651
|
end
|
561
652
|
else
|
562
653
|
not_processed.append({:imei => g["imei"], :description => "Old profile permission error", :error => permiss1})
|
@@ -586,6 +677,44 @@ class Iot
|
|
586
677
|
mongo_client.audit_logger(proc_name, src_ip, input_json, output_json, real_ip)
|
587
678
|
end
|
588
679
|
|
680
|
+
#additional procedure for checking status on iot platform
|
681
|
+
def get_info_by_imeilist_from_iot(login, imei_list)
|
682
|
+
resp_out={}
|
683
|
+
begin
|
684
|
+
dev_id_list = []
|
685
|
+
resss = {}
|
686
|
+
data_from_db = mongo_client.get_imei_info_from_db(imei_list)
|
687
|
+
p data_from_db
|
688
|
+
for g in data_from_db[:body]
|
689
|
+
dev_id_list.append(g["huadata"]["body"]["deviceId"])
|
690
|
+
end
|
691
|
+
credentials = mongo_client.get_iot_oceanconnect_credent(login)
|
692
|
+
if credentials[:code]==200
|
693
|
+
p apid = credentials[:body][:app_id]
|
694
|
+
p secre = credentials[:body][:secret]
|
695
|
+
resp_out = hua_aceanconnect_connector.quer_dev_query_list(apid, secre, dev_id_list)
|
696
|
+
end
|
697
|
+
rescue
|
698
|
+
resp_out = {:code => "500", :message => "get_info_by_imeilist_from_iot: Something wrong", :body => {"devices" => []}}
|
699
|
+
end
|
700
|
+
internal_func.printer_texter(resp_out, "debug")
|
701
|
+
resp_out
|
702
|
+
end
|
703
|
+
|
704
|
+
|
705
|
+
#for internal use. Add new device model
|
706
|
+
def add_model_to_mongo(model, manufacture_id, manufacture_name, device_type, description, note)
|
707
|
+
model = {
|
708
|
+
model: model,
|
709
|
+
ManufacturerID: manufacture_id,
|
710
|
+
ManufacturerNAME: manufacture_name,
|
711
|
+
device_type: device_type,
|
712
|
+
description: description,
|
713
|
+
note: note,
|
714
|
+
created: DateTime.now
|
715
|
+
}
|
716
|
+
mongo_client.imei_insert_model(model)
|
717
|
+
end
|
589
718
|
|
590
719
|
def test()
|
591
720
|
ddd = MongoIot.new(mongoip, mongoport, mongo_database)
|
@@ -595,43 +724,10 @@ class Iot
|
|
595
724
|
#ddd.get_imsi_info_from_db(ff)
|
596
725
|
|
597
726
|
#p ddd.get_profile_id_by_name("1341241")
|
598
|
-
p ddd.
|
727
|
+
p ddd.get_device_type_info_by_model("BGT_PPMC11")
|
599
728
|
end
|
600
729
|
|
601
730
|
|
602
|
-
def testhua()
|
603
|
-
cert_file = cert_path
|
604
|
-
key_file = key_path
|
605
|
-
ddd1 = HuaIot.new(iotplatform_ip, iotplatform_port, cert_file, key_file)
|
606
|
-
#p ddd1.dev_register_verif_code_mode("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "7521234165452")
|
607
|
-
#ddd1.querying_device_id("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "a8834c5e-4b4d-4f0f-ad87-14e916f3d0bb")
|
608
|
-
#ddd1.querying_device_activ_status("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "7521234165452")
|
609
|
-
#ddd1.querying_device_info("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "a8834c5e-4b4d-4f0f-ad87-14e916f3d0bb")
|
610
|
-
list = ["41c0ba82-d771-4669-b766-fcbfbedc17f4", "7521234165452", "feb9c4d1-4944-4b04-a717-df87dfde30f7", "9868e121-c309-4f4f-8ab3-0aa69072caff", "b3b82f35-0723-4a83-90af-d4ea40017194"]
|
611
|
-
#p ddd1.querying_device_direct_conn("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", list)
|
612
|
-
#p ddd1.querying_device_type_list("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa")
|
613
|
-
# ddd1.querying_device_id("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "7521234165452")
|
614
|
-
#p ddd1.dev_register_verif_code_mode("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "45324523452345")
|
615
|
-
|
616
|
-
p devtestid = ddd1.dev_register_passw_code_mode2("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "24235455", "test", "test", "phone", "0")
|
617
|
-
p ddd1.quer_dev_direct_conn_batches("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", [devtestid[:body]["deviceId"], "4c763ea1-be51-4eff-81db-863bc04791bb"])
|
618
|
-
|
619
|
-
#p ddd1.querying_device_info("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "c6e0dfb1-8042-472a-a35d-e984f118d2a6")
|
620
|
-
p "delete start"
|
621
|
-
p ddd1.dev_delete("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", devtestid[:body]["deviceId"])
|
622
|
-
#p ddd1.dev_delete("Cd1v0k2gTBCbpQlMVlW1FVqOSqga", "kbfo5JlBxTIhjVwtjHleWS5Iw5wa", "2881a9cc-cb2a-4b59-8fac-de3aace2324d")
|
623
|
-
end
|
624
|
-
|
625
|
-
|
626
|
-
def testhua2()
|
627
|
-
tt = "{\"deviceId\":\"fad0a417-b6a3-4b0b-abfc-fa2b0af9691a\",\"verifyCode\":\"6cb6dcca\",\"timeout\":180,\"psk\":\"1d16b55d577bc1f2e5e75d416ce6b8a2\"}"
|
628
|
-
#tt = tt.gsub("\\","")
|
629
|
-
#p tt
|
630
|
-
ff = tt.to_s
|
631
|
-
p ff
|
632
|
-
gg = JSON.parse(ff)
|
633
|
-
p gg
|
634
|
-
end
|
635
731
|
|
636
732
|
end
|
637
733
|
|