iot:tutorial:aws-integration
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
iot:tutorial:aws-integration [2020/06/15 11:33] – [Setting up trigger script] atolstov | iot:tutorial:aws-integration [2020/06/15 14:02] – atolstov | ||
---|---|---|---|
Line 268: | Line 268: | ||
===== Testing and Next Steps ===== | ===== Testing and Next Steps ===== | ||
- | ==== To make it possible to post to AWS Broker set up topic for mqtt_pubslish as update and mqtt_get as get. (fix topic' | + | ==== Testing |
Okay, so now it is working AWS MQTT communication and tested successfully. | Okay, so now it is working AWS MQTT communication and tested successfully. | ||
The next step is to reconfigure MQTT topics from '' | The next step is to reconfigure MQTT topics from '' | ||
{{ : | {{ : | ||
- | This will lead the message | + | There is a trigger |
{{ : | {{ : | ||
+ | This settings will lead the message to AWS IoT Core Rules processing, and in the end hitting to DynamoDB table. | ||
+ | |||
==== Setting up trigger script | ==== Setting up trigger script | ||
- | There should be a trigger to change the register' | + | There should be a trigger to change the register' |
+ | For the testing purpose you can do this manually. | ||
{{ : | {{ : | ||
- | ==== __Ensure, | + | After that, check the DynamoDB Table' |
{{ : | {{ : | ||
+ | When you ensure, that data comes to DynamoDB triggered by auxilary WebHMI register change, you can set up the trigger' | ||
+ | |||
As an example there is two practices such as time dependent (oscillator) or quantity depended (decimation) trigger. \\ | As an example there is two practices such as time dependent (oscillator) or quantity depended (decimation) trigger. \\ | ||
- | Oscillator code: | + | \\ |
+ | **//Oscillator code://** \\ | ||
+ | If there is a neccesity to post with predefined frequency, for example 15 second can be done with following script. | ||
- | Decimation code: | + | <code lua> |
+ | a1,a2,a3,a4 = 0,0,0,0 | ||
+ | |||
+ | function TOGGLE(reg) | ||
+ | WriteReg(reg, | ||
+ | end | ||
+ | |||
+ | function main (userId) | ||
+ | |||
+ | if GetReg(" | ||
+ | TOGGLE(" | ||
+ | decimation_counter = 0 | ||
+ | end--if | ||
+ | |||
+ | end--eof | ||
+ | </ | ||
+ | **//Decimation code://** | ||
\\ | \\ | ||
+ | If there is several target register, such us (//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, | ||
+ | end | ||
+ | function main (userId) | ||
+ | if decimation_counter> | ||
+ | | ||
+ | -- check if target registers changed | ||
+ | flag = a1 ~= GetReg(" | ||
+ | or | ||
+ | a2 ~= GetReg(" | ||
+ | or | ||
+ | a3 ~= GetReg(" | ||
+ | or | ||
+ | a4 ~= GetReg(" | ||
+ | | ||
+ | if flag then | ||
+ | decimation_counter = decimation_counter + 1 | ||
+ | end | ||
+ | | ||
+ | -- update local variale values for next scan check | ||
+ | a1 = GetReg(" | ||
+ | a2 = GetReg(" | ||
+ | a3 = GetReg(" | ||
+ | a4 = GetReg(" | ||
+ | | ||
+ | -- DEBUG trace | ||
+ | DEBUG(" | ||
+ | DEBUG(" | ||
+ | DEBUG(" | ||
+ | DEBUG(" | ||
+ | DEBUG(" | ||
+ | | ||
+ | -- decimation_counter for not too often upload to AWS | ||
+ | if decimation_counter >= DECIMATION then | ||
+ | TOGGLE(" | ||
+ | decimation_counter = 0 | ||
+ | end--if decimation_counter | ||
+ | | ||
+ | end--eof | ||
+ | </ | ||
Create ES | Create ES |
iot/tutorial/aws-integration.txt · Last modified: 2021/07/22 07:32 by atolstov