|
| 1 | +# Sending data from VL6180 sensor to Live Objects |
| 2 | + |
| 3 | +This example shows how to send real data from sensor [VL6180X](https://www.st.com/resource/en/datasheet/vl6180x.pdf). Sensor delivers two useful values: |
| 4 | +- ambient light [[lx](https://en.wikipedia.org/wiki/Lux)], |
| 5 | +- distance from disturbance [mm]. |
| 6 | + |
| 7 | +In this use-case [an example of board using sensor](https://kamami.pl/en/kamod-kamami-peripheral-modules/559362-kamodvl6180x-a-module-with-distance-gesture-and-als-sensor.html) was being used. |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +## Our Setup view: |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +## Preparations |
| 16 | +### Installation VL6180X library |
| 17 | +Using **Library Manager** from Arduino IDE (*Tools -> Manage Libraries...*) you need to install library: |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +### Diagram of connection |
| 22 | +Module is controlled via I<sup>2</sup>C and accepts power and signal levels 3.3V. |
| 23 | +MKR1010 WiFi setup diagram: |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +For your board you need to connect power lines (**+3.3V, GND**) and I<sup>2</sup>C lines (**SDA, SCL**) to corresponding VL6180X lines. |
| 28 | + |
| 29 | +### Decoder's preparation for MQTT devices |
| 30 | +If you want to limit amount of data which are being sent from board to Live Objects portal you can use **BINARY** mode which is defined in ```lo.begin()``` in *7_distance_and_light_sensor.ino*: ```lo.begin(MQTT, BINARY, true);```. In this case both values: ambient light (1 byte) and distance (4 bytes) will be sent as only five bytes (see terminal output in point 6). |
| 31 | + |
| 32 | +To achieve this goal, you need to create **private binary decoder** in Live Objects portal. Use: *Data -> Decoders -> +Add*. You an enter data as below and click **Save**. |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +<br> |
| 37 | + |
| 38 | +### MQTT interface modification |
| 39 | + |
| 40 | +You need to select your device for which you want to activate previously created **private binary decoder**. Click selected device from the list uder tab **Devices**. |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +<br> |
| 45 | + |
| 46 | +Then click **Identity** and next click icon in red circle. After that in field **Decoder** you can select your decoder. Clicking **Save** finishes this step and activates our private decoder **VL6180Xbin** for MQTT interface for selected device. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +## Running |
| 51 | +First of all, be sure that you installed the required libraries and generated an API key mentioned in the main **README.md** file, then: |
| 52 | +1. Open *7_distance_and_light_sensor.ino* sketch using Arduino IDE, |
| 53 | +2. Replace ```const char SECRET_LIVEOBJECTS_API_KEY[]="...";``` in *arduino_secrets.h* with API key you generated, |
| 54 | +3. Define necessary credentials for your board in *arduino_secrets.h*: |
| 55 | +- for WiFi boards: |
| 56 | + - ```extern const String SECRET_SSID = "...;``` |
| 57 | + - ```extern const String SECRET_WIFI_PASS = "...";``` |
| 58 | +- for cellular boards: |
| 59 | + - ```extern const String SECRET_PINNUMBER = "...";``` (if needed), |
| 60 | + - ```extern const String SECRET_APN = "";``` (if needed), |
| 61 | + - ```extern const String SECRET_APN_USER = "...";``` (if needed), |
| 62 | + - ```extern const String SECRET_APN_PASS = "...";``` (if needed), |
| 63 | +4. In ```lo.setSecurity()``` select security mode using ```TLS``` or ```NONE``` according to board abilities shown in **Compatibility** point in main **README.md**, |
| 64 | +5. Upload *7_distance_and_light_sensor.ino* sketch to your board. |
| 65 | +6. In your terminal window you should see similiar output: |
| 66 | + |
| 67 | +``` |
| 68 | +15:31:22.732 -> |
| 69 | +15:31:22.732 -> VL6180X sensor |
| 70 | +15:31:22.732 -> Model ID = 180 |
| 71 | +15:31:22.732 -> Model Rev = 13 |
| 72 | +15:31:22.732 -> Module Rev = 12 |
| 73 | +15:31:22.732 -> Manufacture Date = 16/11/14 Phase: 1 |
| 74 | +15:31:22.732 -> |
| 75 | +15:31:23.762 -> |
| 76 | +15:31:23.762 -> *** Live Objects for Arduino MKR boards, revision 2.1.0 *** |
| 77 | +15:31:24.526 -> [INFO] WiFi firmware version 1.2.4 |
| 78 | +15:31:24.526 -> [INFO] Attempting to connect to SSID: EdekAD57BA |
| 79 | +15:31:28.279 -> |
| 80 | +15:31:28.279 -> [INFO] Connecting to MQTT broker mqtt.liveobjects.orange-business.com:1883 |
| 81 | +15:31:30.439 -> [INFO] You're connected to the MQTT broker |
| 82 | +15:31:30.439 -> Sampling data |
| 83 | +15:31:30.572 -> Sending data to Live Objects |
| 84 | +15:31:30.572 -> [INFO] Publishing message on topic: dev/v1/data/binary |
| 85 | +15:31:30.572 -> [INFO] 4041A9C28F |
| 86 | +15:31:35.554 -> Sampling data |
| 87 | +15:31:35.687 -> Sending data to Live Objects |
| 88 | +15:31:35.687 -> [INFO] Publishing message on topic: dev/v1/data/binary |
| 89 | +15:31:35.687 -> [INFO] 4841AEE148 |
| 90 | +... |
| 91 | +``` |
| 92 | + |
| 93 | +## Verify |
| 94 | +**Is device online:** |
| 95 | +If all went fine under **Devices** tab on Live Live Objects portal you should see online your device identified by its modem IMEI or WiFi MAC address: |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +**Is device sending data:** |
| 100 | +Under **Data** tab on Live Objects portal you should see messages sent by your device, along with values eg. *{ "distance": 110, "amblight": 192.63 }* |
| 101 | + |
| 102 | + |
| 103 | + |
| 104 | +<br><br> |
| 105 | + |
| 106 | +*** |
| 107 | +## SMS (cellular boards) |
| 108 | + |
| 109 | +## Preparations |
| 110 | + |
| 111 | +### SMS device creation |
| 112 | +You need to manually add your cellular device as it is described in [this point](../6_sms_send_data/README.md). |
| 113 | + |
| 114 | +### Decoder's preparation for SMS devices |
| 115 | +If you want to limit amount of data which are being sent from board to Live Objects portal you can use pure **TEXT** mode which is defined in ```lo.begin()``` in *7_distance_and_light_sensor.ino*: ```lo.begin(SMS, TEXT, true);```. In this case both values: ambient light and distance will be transmitted as raw text. |
| 116 | + |
| 117 | +To achieve this goal, you need to create **private sms decoder** in Live Objects portal. Use: *Data -> Decoders -> +Add*. You an enter data as below and click **Save**. |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | +### SMS interface modification |
| 122 | + |
| 123 | +You need to modify SMS interface for you device in similar way as for MQTT device selecting **VL6180Xsms** decoder. |
| 124 | + |
| 125 | +## Running |
| 126 | +First of all, be sure that you installed the required libraries and generated an API key mentioned in the main **README.md** file, then: |
| 127 | +1. Open *7_distance_and_light_sensor.ino* sketch using Arduino IDE, |
| 128 | +2. Replace ```const char SECRET_LIVEOBJECTS_API_KEY[]="...";``` in *arduino_secrets.h* with API key you generated, |
| 129 | +3. Specify the number of sever (gate) in *arduino_secrets.h*: |
| 130 | + - ```extern const String SECRET_SERVER_MSISDN = "...";```, |
| 131 | +4. In ```lo.setSecurity()``` select security mode ```NONE``` |
| 132 | +5. Upload *7_distance_and_light_sensor.ino* sketch to your board. |
| 133 | +6. In your terminal window you should see similiar output: |
| 134 | + |
| 135 | +``` |
| 136 | +3:00:46.470 -> VL6180X sensor |
| 137 | +13:00:46.470 -> Model ID = 180 |
| 138 | +13:00:46.470 -> Model Rev = 13 |
| 139 | +13:00:46.470 -> Module Rev = 12 |
| 140 | +13:00:46.470 -> Manufacture Date = 16/11/14 Phase: 1 |
| 141 | +13:00:46.470 -> |
| 142 | +13:00:47.467 -> |
| 143 | +13:00:47.467 -> *** Live Objects for Arduino MKR boards, revision 2.1.0 *** |
| 144 | +13:00:52.151 -> [INFO] Connecting to cellular network |
| 145 | +13:01:00.558 -> |
| 146 | +13:01:00.758 -> [INFO] You're connected to the network |
| 147 | +13:01:00.758 -> Sampling data |
| 148 | +13:01:00.891 -> Sending data to Live Objects |
| 149 | +13:01:00.891 -> [INFO] Publishing message: 122;310.17; |
| 150 | +13:01:06.740 -> Sampling data |
| 151 | +13:01:06.840 -> Sending data to Live Objects |
| 152 | +13:01:06.840 -> [INFO] Publishing message: 255;300.67; |
| 153 | +... |
| 154 | +``` |
| 155 | + |
| 156 | +## Verify |
| 157 | + |
| 158 | +You can verify if device is online and data are delivered in the same way as it is described for MQTT device. |
0 commit comments