User Tools

Site Tools


iot:tutorial:aws-integration

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
iot:tutorial:aws-integration [2020/06/12 12:18] atolstoviot:tutorial:aws-integration [2020/07/06 11:48] atolstov
Line 232: Line 232:
 {{ iot:aws:wh:wh_test_via_mqttfx_connections.png?direct |}} {{ iot:aws:wh:wh_test_via_mqttfx_connections.png?direct |}}
  
-For know, it is WebHMI can post the data from real devices to various AWS Thingsvisualise with QuickSight tool and store this data in DynamoDB with possibility to import as .csv file to S3 bucket for example.+For know, it is WebHMI can post the data from real devices to AWS MQTT Clientwhich allow update to various AWS Thing's Shadow. The data could be visualised data with QuickSight tool and stored this data in DynamoDB with possibility to import as .csv file to S3 bucket for example.
  
  
Line 260: Line 260:
  
 </code> </code>
-{{ iot:aws:shadow:mqttfx_to_aws_connected.png?direct |}}+{{ :iot:aws:wh_upd_script.png?direct |}}
 To check the result of script work let’s check ''“iot-test”'' subscribed topic in MQTT.fx. To check the result of script work let’s check ''“iot-test”'' subscribed topic in MQTT.fx.
  
Line 268: Line 268:
  
 ===== Testing and Next Steps =====  ===== Testing and Next Steps ===== 
 +==== Testing ====
  
-Test WebHMI can post to AWS shadow, +Okay, so now it is working AWS MQTT communication and tested successfully. 
-create Actions, apply pols, +The next step is to reconfigure MQTT topics from ''iot-test'' to Thing's Shadow ''.../update'' topic. 
-check the DynamoDB updatecheck Kibana metric created.+{{ :iot:aws:wh:wh_to_aws_update_and_trigger.png?direct |}} 
 +There is a trigger to run script, by the register's value change to post a message to AWS.   
 +{{ :iot:aws:wh:wh_to_aws_update_scripts.png?direct |}} 
 +This settings will lead the message to AWS IoT Core Rules processingand in the end hitting to DynamoDB table.
  
-Work with Kibana+==== Setting up trigger script  ==== 
 +There should be a trigger to change the register's value to post a message to AWS, because of too short duration of scan and superfluity of update frequincy for cloud data processing. 
 +For the testing purpose you can do this manually. 
 +{{ :iot:aws:wh:wh_to_aws_update_triggered.png?direct |}} 
 +After that, check the DynamoDB Table's Item append. 
 + 
 +{{ :iot:aws:wh:ddb_update.gif?direct |}} 
 +When you ensure, that data comes to DynamoDB triggered by auxilary WebHMI register change, you can set up the trigger's toggle by script. 
 + 
 +As an example there is two practices such as time dependent (oscillator) or quantity depended (decimation) trigger. \\  
 + \\  
 +**//Oscillator code://**  \\  
 +If there is a neccesity to post with predefined frequency, for example 15 second can be done with following script. 
 + 
 +<code lua> 
 +a1,a2,a3,a4 = 0,0,0,0 
 + 
 +function TOGGLE(reg)  
 +    WriteReg(reg, 1 - R(reg)) 
 +end  
 + 
 +function main (userId) 
 +     
 +    if GetReg("GT") % 15  == 0 then -- Global Time (T0@Internal) 
 +                TOGGLE("aws_trigger"
 +                decimation_counter = 0 
 +    end--if 
 +     
 +end--eof 
 +</code> 
 +**//Decimation code://** 
 +\\  
 +If there is several target register, such as //counter, counter2, etc.//, but if it changes too often, this code will help to decimate the output trigger signal. 
 +<code lua> 
 +a1,a2,a3,a4 = 0,0,0,0 
 + 
 +decimation_counter = 0; 
 +DECIMATION = 10 
 + 
 +function TOGGLE(reg)  
 +    WriteReg(reg, 1 - R(reg)) 
 +end 
 + 
 +function main (userId) 
 +                            if decimation_counter>1 then DEBUG("decimation_counter:"..decimation_counter) end 
 +                             
 +                            -- check if target registers changed 
 +    flag =  a1 ~= GetReg("counter")  
 +                        or 
 +            a2 ~= GetReg("counter2"
 +                        or 
 +            a3 ~= GetReg("counter3"
 +                        or 
 +            a4 ~= GetReg("counter4"
 +             
 +    if flag then  
 +        decimation_counter = decimation_counter + 1 
 +    end 
 +     
 +                            -- update local variale values for next scan check 
 +    a1 = GetReg("counter") -- Counter 1 (D0@Internal) 
 +    a2 = GetReg("counter2") -- Counter 2 (D0@Internal) 
 +    a3 = GetReg("counter3") -- Counter 3 (D0@Internal) 
 +    a4 = GetReg("counter4") -- Counter 4 (D0@Internal) 
 +     
 +                            -- DEBUG trace 
 +                            DEBUG("aws_trigger" .. ":" .. R("aws_trigger") .. " flag:" .. tostring(flag)) 
 +                            DEBUG("a1:"..a1) 
 +                            DEBUG("a2:"..a2) 
 +                            DEBUG("a3:"..a3) 
 +                            DEBUG("a4:"..a4) 
 +                             
 +                            -- decimation_counter for not too often  upload to AWS 
 +    if decimation_counter >= DECIMATION then 
 +            TOGGLE("aws_trigger"
 +            decimation_counter = 0 
 +    end--if decimation_counter 
 +     
 +end--eof 
 +</code> 
 + 
 +==== Next steps ==== 
 +==== Create visualisation environment ==== 
 +To use Kibana visualisation firstly you need to run an ElasticSearch engine deployed on virtual machine.  
 +So the idea is to create ElasticSearch Instance with Kibana plugin on-board. 
 +Fortunately, there is a detached Menu item in Analytics AWS Services group.  
 +{{ :iot:tutorial:aws_es_service.png?direct |}} 
 +So, crete a new one instance with following settings. 
 +{{ :iot:tutorial:es_type.png?direct |}} 
 +Specify domain name and instance type (size, e.g. t2.small). 
 +{{ :iot:tutorial:es_domain.png?direct |}} 
 +Specify the access policy, the good practice is a public one, but there is should IP resctiction be specified.  
 +{{ :iot:tutorial:es_security.png?direct |}} 
 +[[https://www.myip.com/|To check IP use myip.com]]. 
 +{{ :iot:tutorial:es_myip_blur.com.png?direct |}} 
 +The first line has your current IP.  
 +As a CIDR block you can rewrite you IP as XXX.XXX.XXX.XXX/16, where 16 is a number or bit, that can be changed to still satisfy the condition, so that will form a IP adresses range, which will protect your from ISP pool IP mascarading.  
 +Otherwise, copy your IP to field as is. 
 +\\  
 +In the end, this will lead your to this settings. Review it and confirm creation if it fine. 
 +{{ :iot:tutorial:es_review.png?direct |}} 
 +After the creation, in several minutes it will be endpoint adress created  
 +{{ :iot:tutorial:es_success_loading.png?direct |}} 
 +Wait until it would be done. 
 +{{ :iot:tutorial:es_active.png?direct |}} 
 +At this moment, you will have access to Kibana plugin, the following link is provided above. 
 +{{ :iot:tutorial:es_kibana_loaded.png?direct |}} 
 +==== Create a DynamoDB to Elasticsearch bridge using Lambda function ==== 
 + 
 + 
 + 
 +<del> 
 +0) formulate the payload in JSON and clarify the DDBv2 rule 
 +1) Create Lambda function, set up destinations, triggers 
 + 
 +2) test function successfully. 
 + 
 +3)check Kibana metric created. 
 + 
 +4) Work with Kibana (demo visualisation)</del>
  
  
  
  
iot/tutorial/aws-integration.txt · Last modified: 2021/07/22 07:32 by atolstov

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki