ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
***The Trigger of Devicebit*** is the simple form of IFTTT(IF THIS THEN THAT). Different alerts (E-mail or twitter) can be triggered  according to one value or value combination (edge trigger is supported).   This tutorial mainly introduces the procedures to trigger E-mail or Twitter alert and send report periodically.   # Hardware    No hardware is required. Only simulate data-upload by API testing tool  provided by DeviceBit platform to test trigger functions and send report periodically.   # **Procedures**   # 1 Register DeviceBit Account (www.devicebit.com)   ![](http://upload-images.jianshu.io/upload_images/5875248-61596ba6f8c348a0.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)   Pic.1 Sign Up    # 2 Add Sensors Add ***My Device, Sensors: Humidity and Temperature*** according to previous tutorials (Please refer Chapter 1&2 for details. Note: note down the sensor ID, for it will be used in Api calling.)  ## 2.1 Add A Device After login, go to ***My Devices -> Devices->Add a Device***     First, click on ***Devices*** ***->***  ***Add A Device***, as the picture1 below. After entering the related  information, click on ***Save***.  ![](http://upload-images.jianshu.io/upload_images/5875248-48212464bc1a9175.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.2 Add A Device        ## 2.2 Add Sensors The next step is to add the humitity & temperature sensor. Go to ***My Devices-> Sensors&Controllers->Sensor***, click on ***Add***.   ![](http://upload-images.jianshu.io/upload_images/5875248-e555bbbf1aec13ab.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.3  Sensors       Then there will be the ***Add A Sensor*** page.    ![](http://upload-images.jianshu.io/upload_images/5875248-c064ed4636888cb2.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)   Pic.4  Add Humidity         As the above picture shows, enter Humidity for ID (Note down the ***ID*** for it will be used in Api calling). Select ***Humidity Monitoring*** for ***Type***. Seclet ***%*** for ***Unit***. Select ***My Device*** which is created previously. Enter ***Humidity*** for ***Name***. If you want others could view the humidity data, tick ***Yes*** for ***Public*** item.   Add the ***Temperature*** sensor in the same way. Please see the following picture.    ![](http://upload-images.jianshu.io/upload_images/5875248-c102d4d8fb9d2666.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)  Pic.5 Add Temperature   After setting up, as picture 5 shows, note down the ***ID*** because it will be used in Api calling.   ![](http://upload-images.jianshu.io/upload_images/5875248-1018cc83f69d98d9.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.6  Sensor ID     # 3 Variable Settings Go to  ***IOT applications ->Variables Settings ->Add A Variable***  (Please refer to Chapter9 for details.) to set the variables such as ***hour, date, humidity, temperature*** etc, and add expressions, as the following picture shows.    ![](http://upload-images.jianshu.io/upload_images/5875248-b8fec42d68d4b181.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.9  Variable Settings   First, set different Twitter content, ***Good morning, Good afternoon*** or ***Good evening*** according to the system variable ***Hour***. Click on ***Add Expressions***, and fill in the information as follows:   ![](http://upload-images.jianshu.io/upload_images/5875248-bf85224f1bacd1d5.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.10 Hour Settings   Note the ***Type ***select*** System Variables ***. The system variables including the*** hour , date*** and ***time***. Select ***Hour*** here.***Decimal Places*** leave blank, for decimal is not involved here. Tick ***Yes*** at ***Whether to output text?***Then, click on ***Test***, we can see that the current time is 11 o’clock, and the text is ***Good Morning***! (For the time is at the range 8-12)   ![](http://upload-images.jianshu.io/upload_images/5875248-2429dbb6d21fe376.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.11 Test For Hour   Next, set up ***Date*** in the same way. Settings for date are very simple. Ignore ***Enable text output*** for there is no need to set it. The settings and test results are as follows:   ![](http://upload-images.jianshu.io/upload_images/5875248-d076f37694309338.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)   Pic.12 Settings &Test For Date   Finally, set the Twitter text according to different measured humidity values. Here, select ***Sigle Sensor*** for ***Type,*** select ***My Device*** and ***Humidity*** for ***Reference Value***. Since all the values are integers, the decimal places do not need to be set. If the measured values are decimals, you can set the decimal places here. The format is .0, .00 and so on. The logical relationship between the output text and the value range is as follows, and you can define it by yourself. Then, click on ***Test*** to check the result.   ![](http://upload-images.jianshu.io/upload_images/5875248-5d32fc80cd21a179.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)   Pic.13 Settings & Test For Humidity   # 4 Text Settings   Go to  ***IOT applications ->Text Edit ->Add Sending Content*** (Please refer Chapter9 for details. ) to edit the sending text. Please see the following picture.    Edit text: Click on ***Text Edit ->Add Sending Content***   ![](http://upload-images.jianshu.io/upload_images/5875248-8f6bca2e6232fedf.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)   Pic.14 Text Edit   The settings and test result are as follows.   ![](http://upload-images.jianshu.io/upload_images/5875248-db39f0c5d719cbda.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)   Pic.15 Settings & Test For Text   The returned content for [[ ]] is the returned value of the system variable in [[ ]], the measured value of the sensor in [[ ]], or the more complex logic operation result of the measured values of the sensor in [[ ]]. For example, the returned content for [[date]] is the current date. While, the content for the two braces {{}} is the Twitter Text corresponding with the value range of the variable in {{}}. For example, in the following picture, the current humidity is 57%. According to the previous logic relationship set for the value range from 41 to 70, the returned text content for {{Humidity}} is ***It is comfortable!*** After setting, you can click on ***Test*** to see whether the settings are correct.   ![](http://upload-images.jianshu.io/upload_images/5875248-d78b6991683135cc.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)  Pic.16  Text Edit   # 5 Command   Go to  ***IOT applications->Command Settings ->Add A Command***     Enter ***Open LED*** for ***Title***, seclect ***My Device*** for ***Device***, select ***Custom Method*** for ***Method Name***, and enter ***turnledon*** in the blank. Please see the picture below.   ![](http://upload-images.jianshu.io/upload_images/5875248-632eeea7366fbf4a.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.17  Command Settings       # 6 Contro Scheme   Go to  ***IOT applications ->Multi-Control ->Add A Control Unit***      Enter ***Open*** for ***Name***, tick ***Open LED*** for ***Command***. Please see the picture below. The purpose of this step is to trigger the LED on. ![](http://upload-images.jianshu.io/upload_images/5875248-0869819d4e30d0eb.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.18  Control Unit     #7  Trigger Settings Next, let's set the trigger.    Go to  ***IOT applications->Triggers->Add A Trigger***    ![](http://upload-images.jianshu.io/upload_images/5875248-153f2fa459d747b1.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.19 Trigger Settings   Enter ***Temperature Test*** for ***Description***, select ***Temperature*** for ***Sensor***, enter ***30*** in the blank part after ***Greater than*** for ***Edit Condition***; untick ***Endge Trigger***.   Next, ***Enable Text Sending***: tick ***Yes*** then, the following page will appear,    ![](http://upload-images.jianshu.io/upload_images/5875248-3eead144d7424ff7.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.20  Text Settings      Let's move on to ***Sending Content***  ***Sending content***: select ***Temperature*** ***Enable Control Unit***: select Open ***Minimal Trigger Interval*** : 10 (default value) ***Enable***:  tick ***Yes***. Then, the trigger is on. Please refer to the following picture.    ![](http://upload-images.jianshu.io/upload_images/5875248-c45ea9b383ccd608.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.21  Temperature Test      Set up the humidity trigger in the same way.   ![](http://upload-images.jianshu.io/upload_images/5875248-7e281cb3e8db2644.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.22 Humidity Test   ![](http://upload-images.jianshu.io/upload_images/5875248-c73c1eba9bc655a6.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.23  Trigger List     Thus, the triggers of temperature and humidity are set up, as the above picture shows .   # 9 API Test The simplest way to test the triggers is to simulate data-upload by using API testing tool.**    At the home page (the website is www.devicebit.com) click on ***Documentation*** ![](http://upload-images.jianshu.io/upload_images/5875248-0ae780c2aaa4964e.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)  Pic.24 Home Page   and then go to ***API Directory-> Sensor ->Upload Sensor Data***   ![](http://upload-images.jianshu.io/upload_images/5875248-f8be60a408c5e748.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)   Pic.25  API Directory      Website http://www.DeviceBit.com/dev/apiList?version=1&sk=69    http://www.DeviceBit.com/dev/apitest/3   ![](http://upload-images.jianshu.io/upload_images/5875248-d56f86a2d7d23e12.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) Pic.26 Online test    Click on ***on-line test*** ![](http://upload-images.jianshu.io/upload_images/5875248-1bca4d9f403c02fa.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)   Pic.27 API Testing Tool  Enter your ***Userkey***  Enter ***Device ID*** at API URL  http://www.DeviceBit.com/api/V1/gateway/UpdateSensors/{device ID} [(01 for exampe)](http://www.lewei50.com/api/V1/gateway/UpdateSensors/%E4%BD%A0%E7%9A%84%E7%BD%91%E5%85%B3%E5%8F%B7)   [After entering the device ID, the APIURL is:](http://www.lewei50.com/api/V1/gateway/UpdateSensors/%E4%BD%A0%E7%9A%84%E7%BD%91%E5%85%B3%E5%8F%B7)   http://www.DeviceBit.com/api/V1/gateway/UpdateSensors/01    ![](http://upload-images.jianshu.io/upload_images/5875248-401f50dc6d5ef74c.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)  Pic.28 Userkey&Device ID    Change ***T1*** to ***Temperature*** for ***Name***; change ***1*** to ***32*** for ***Value***;    Change ***01H1*** to ***Humidity*** for ***Name***; change ***96.2***  to ***75*** for ***Value***.   ![](http://upload-images.jianshu.io/upload_images/5875248-1c0d7b59c1b061c4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)  Pic.29  Post Data   Click on ***Run***, and then the result will be displayed                       .       ![](http://upload-images.jianshu.io/upload_images/5875248-9a90e212c9323d95.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ![](http://upload-images.jianshu.io/upload_images/5875248-1f4dec43f65dbab5.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)  Pic.30 Request Detail    At last, Go to ***My IOT -> Sensors&Controllers->Sensor List***, you will see the following value.  ![](http://upload-images.jianshu.io/upload_images/5875248-bd4861f4d7594b5d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)  Pic.31 The Value     You have already received SMS, Email or send Weibo, and the LED is on!