├── .babelrc ├── .buckconfig ├── .env.example ├── .flowconfig ├── .gitattributes ├── .gitignore ├── .watchmanconfig ├── LICENSE.md ├── README.md ├── __tests__ ├── index.android.js └── index.ios.js ├── android ├── app │ ├── BUCK │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ └── fonts │ │ │ ├── Entypo.ttf │ │ │ ├── EvilIcons.ttf │ │ │ ├── FontAwesome.ttf │ │ │ ├── Foundation.ttf │ │ │ ├── Ionicons.ttf │ │ │ ├── MaterialCommunityIcons.ttf │ │ │ ├── MaterialIcons.ttf │ │ │ ├── Octicons.ttf │ │ │ ├── SimpleLineIcons.ttf │ │ │ ├── Zocial.ttf │ │ │ ├── fontello.ttf │ │ │ └── icons.ttf │ │ ├── java │ │ └── com │ │ │ └── cayennesampleapp │ │ │ ├── MainActivity.java │ │ │ └── MainApplication.java │ │ └── res │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ └── values │ │ ├── strings.xml │ │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── keystores │ ├── BUCK │ └── debug.keystore.properties └── settings.gradle ├── app.js ├── app.json ├── index.android.js ├── index.ios.js ├── ios ├── CayenneSampleApp-tvOS │ └── Info.plist ├── CayenneSampleApp-tvOSTests │ └── Info.plist ├── CayenneSampleApp.xcodeproj │ ├── project.pbxproj │ └── xcshareddata │ │ └── xcschemes │ │ ├── CayenneSampleApp-tvOS.xcscheme │ │ └── CayenneSampleApp.xcscheme ├── CayenneSampleApp │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ │ └── LaunchScreen.xib │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ └── main.m └── CayenneSampleAppTests │ ├── CayenneSampleAppTests.m │ └── Info.plist ├── js ├── components │ ├── Button │ │ ├── index.js │ │ └── styles.js │ ├── Device │ │ └── index.js │ ├── Footer │ │ └── index.js │ ├── Header │ │ └── index.js │ ├── Instruction │ │ └── index.js │ ├── ModalBox │ │ └── index.js │ ├── Sensor │ │ └── index.js │ ├── TextBox │ │ ├── index.js │ │ └── styles.js │ ├── common-styles.js │ └── index.js ├── config │ ├── config.json │ ├── images.js │ ├── index.js │ ├── session.js │ └── settings.js ├── images │ ├── graphic-gateway-placement.png │ ├── graphic-gateway-setup.png │ ├── graphic-setup-elsys.png │ ├── myDevicesWhite.png │ ├── mydevices.png │ └── tankBg.jpg ├── lib │ ├── auth.interceptor.js │ ├── auth.service.js │ ├── history.service.js │ ├── index.js │ ├── navigation.service.js │ ├── platform.service.js │ ├── rule.service.js │ ├── storage.service.js │ ├── streaming.service.js │ └── utils.service.js ├── routes │ └── router.js └── screens │ ├── add-device.js │ ├── alerts.js │ ├── gateway-setup.js │ ├── index.js │ ├── login │ ├── create-email.js │ ├── create-name.js │ ├── forgot-password.js │ └── login-screen.js │ ├── sensor-map.js │ ├── sensor-setup.js │ ├── splash.js │ └── status-screen.js ├── jsconfig.json ├── package-lock.json ├── package.json └── resources └── fonts └── fontello.ttf /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["react-native", "react-native-dotenv"] 3 | } 4 | -------------------------------------------------------------------------------- /.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | # Cayenne Cloud API Creds (Never share your app secret!) 2 | APP_KEY= 3 | APP_SECRET= 4 | 5 | 6 | # Authentication Host 7 | AUTH_HOST=https://va-prod-auth/ 8 | 9 | # Main platform host 10 | API_HOST=https://platform.mydevices.com/v1.1/ 11 | 12 | # Streaming Host 13 | STREAMING_HOST=https://va-prod-stream/stream/ 14 | 15 | # History Host 16 | HISTORY_HOST=https://va-prod-delorean/devices/ 17 | 18 | # Rules Service Host 19 | RULES_HOST=https://va-prod-executor/ 20 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore unexpected extra "@providesModule" 9 | .*/node_modules/.*/node_modules/fbjs/.* 10 | 11 | ; Ignore duplicate module providers 12 | ; For RN Apps installed via npm, "Libraries" folder is inside 13 | ; "node_modules/react-native" but in the source repo it is in the root 14 | .*/Libraries/react-native/React.js 15 | .*/Libraries/react-native/ReactNative.js 16 | 17 | [include] 18 | 19 | [libs] 20 | node_modules/react-native/Libraries/react-native/react-native-interface.js 21 | node_modules/react-native/flow 22 | flow/ 23 | 24 | [options] 25 | emoji=true 26 | 27 | module.system=haste 28 | 29 | experimental.strict_type_args=true 30 | 31 | munge_underscores=true 32 | 33 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 34 | 35 | suppress_type=$FlowIssue 36 | suppress_type=$FlowFixMe 37 | suppress_type=$FixMe 38 | 39 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-2]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 40 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-2]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 41 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 42 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 43 | 44 | unsafe.enable_getters_and_setters=true 45 | 46 | [version] 47 | ^0.42.0 48 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | project.xcworkspace 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | 44 | # fastlane 45 | # 46 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 47 | # screenshots whenever they are needed. 48 | # For more information about the recommended setup visit: 49 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 50 | 51 | fastlane/report.xml 52 | fastlane/Preview.html 53 | fastlane/screenshots 54 | 55 | 56 | .env 57 | .vscode/ 58 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 myDevices 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deprecated. 2 | 3 | ### Please visit [mydevices.com](https://mydevices.com) and our [docs](https://docs.mydevices.com) page for more information and new APIs on how to build applications with myDevices. 4 | 5 | 6 | --- 7 | 8 | 9 | 10 | #### Cayenne Cloud API Sample App 11 | 12 | This repo contains a sample app walking through the Authentication process along with device pre-provisioning. 13 | 14 | --- 15 | 16 | ## Prereqs 17 | 1. Run `npm install` in root 18 | 2. This app was built using React Native and a getting start guide can be found [here] (https://facebook.github.io/react-native/docs/getting-started.html#installing-dependencies) which will be needed to run the app simulation 19 | - Use your preferred React Native IDE (I used [Visual Studio Code](https://code.visualstudio.com/) with React Native Tools plugin) 20 | 3. Create or log into your Cayenne account at https://cayenne.mydevices.com/cayenne/login 21 | 4. Obtain your Cayenne Cloud API app key and secret by clicking the Create App button. 22 | 5. Create an `.env` file using the `.env.example` file and input your app key/secret values 23 | * Note, when making changes to `.env`, please edit `js/config/settings.js` with any blank line/whitespace as per react-native-dotenv [Troubleshooting](https://github.com/zetachang/react-native-dotenv#troubleshooting) 24 | 6. You should now be able to run the Sample App and land on the login screen (implicit/explicit logins will not work at this point) 25 | - You can run the app simulation by using `react-native run-ios` or `react-native run-android` 26 | 27 | ### Example Walkthrough 28 | 29 | In this section we will cover practical examples of putting the Cayenne Cloud API into use. 30 | 31 | The example walkthrough shown here is arranged as a narrative that walks you through the various API-related topics required to implement each screen found in the **Cayenne API Sample App**. You can find more information about the Cayenne Cloud API [here](http://mdswp-staging.mydevices.com/cayenne/docs/#cayenne-api) 32 | 33 | 1. **[Application redirects](#application-redirects)** - Application Redirects. 34 | 2. **[Creating an account](#creating-an-account)** - Creating a new account. 35 | 3. **[Logging into an account](#logging-into-account)** - Log into our account. 36 | 4. **[Resetting password](#reset-password)** - Resetting the account password. 37 | 5. **[Provisioning devices](#provisioning-devices)** - Provisioning a device so that it can be later activated. 38 | 6. **[Activating devices](#activating-a-device)** - Activating devices. 39 | 7. **[Get real-time device data](#getting-real-time-device-data)** - Fetching device status and current device data. 40 | 8. **[Remote control](#remote-control)** - Controlling devices remotely. 41 | 9. **[Device History](#getting-device-history)** - Fetching historical device data. 42 | 10. **[Alerts](#alerts)** - Creating and managing Alerts. 43 | 11. **[Multi-Tenant](#multi-tenant)** - Creating and managing Users. 44 | 45 | #### Application Redirects 46 | 47 | Your appplication redirects will be used to retrieve an oAuth token using your **App Key** and **App Secret**. 48 | 49 | First you must retrieve an authorization token to modify your application which is done by making a `POST` to `https://auth.mydevices.com/oauth/token` with the following payload: 50 | ``` 51 | { 52 | "grant_type": "password", 53 | "email": "YOUR EMAIL", 54 | "password": "YOUR PASSWORD 55 | } 56 | ``` 57 | 58 | Example `POST` curl call: 59 | `curl -X POST -H 'Content-Type: application/json' 'https://auth.mydevices.com/oauth/token' -d '{"grant_type": "password", "email": "YOUR EMAIL", "password": "YOUR PASSWORD"}'` 60 | 61 | A successful response will return the following: 62 | ``` 63 | { 64 | "access_token": "YOUR AUTH TOKEN", 65 | "refresh_token": "YOUR REFRESH TOKEN" 66 | } 67 | ``` 68 | 69 | Using your `access_token` from successful `oauth/token` POST, you can view all your applications for your account by making a `GET` to `https://auth.mydevices.com/applications` 70 | 71 | Example `GET` curl call: 72 | `curl -X GET -H 'Authorization: Bearer ACCESS_TOKEN' 'https://auth.mydevices.com/applications'` 73 | 74 | A successful response will return with the following: 75 | ``` 76 | { 77 | "id": "YOUR APP ID", 78 | "name": "Beta App", 79 | "description": "This is a beta app created with Cayenne API", 80 | "secret": "YOUR APP SECRET", 81 | "status": "active", 82 | "updated_at": "YYYY-MM-DDTHH:MM:SS.mmmZ", 83 | "created_at": "YYYY-MM-DDTHH:MM:SS.mmmZ" 84 | } 85 | ``` 86 | 87 | Note: Your application's name and description will currently have default values during Beta phase. 88 | 89 | To update your application's `redirect_uri`, you will need to make a `POST` to `https://auth.mydevices.com/applications/{YOUR APP ID}/redirects` with the following payload: 90 | ``` 91 | { 92 | "redirect_uri": "YOUR REDIRECT URI" 93 | } 94 | ``` 95 | 96 | Example curl call using the sample app's redirect URI. 97 | `curl -X POST -H 'Authorization: Bearer ACCESS_TOKEN' 'https://auth.mydevices.com/applications/{app id}/redirects' -d '{"redirect_uri": "sample://implicit"}'` 98 | 99 | This should be repeated for `redirect_uri: sample://explicit` as `sample://explicit` and `sample://implicit` are redirects that will be used by the sample app on oAuth login. 100 | 101 | It is also recommended to add `http://example.com/redirect` as an additional redirect URI for **[Logging into an account](#logging-into-account)**. 102 | 103 | #### Creating an account 104 | 105 | In order to use the Cayenne Sample App, users are reqired to have an account. If they do not already have an account, they can create one directly from the app. To begin, the user is asked to provide the necessary account information used to create the new account. 106 | 107 |


Sample App Create Account 1

108 | 109 |


Sample App Create Account 2

110 | 111 | Once we have the information from the user, we can use the Cayenne Cloud API to create a new account. If the account creation is successful, we can proceed with logging the user into their account. 112 | 113 | In order to create an account, you will need to use the following endpoint: `https://auth.mydevices.com/users` with the following payload: 114 | ``` 115 | { 116 | "first_name": "YOUR FIRST NAME", 117 | "last_name": "YOUR LAST NAME", 118 | "email": "YOUR EMAIL", 119 | "password": "YOUR PASSWORD" 120 | } 121 | ``` 122 | 123 | Example `POST` curl call: 124 | `curl -X POST -H 'Content-Type: application/json' 'https://auth.mydevices.com/users' -d '{"first_name": "joe", "last_name": "smith", "email": "EMAIL", "password": "PASSWORD"}'` 125 | 126 | A successful response will return the following: 127 | ``` 128 | { 129 | "access_token": "YOUR AUTH TOKEN", 130 | "refresh_token": "YOUR REFRESH TOKEN" 131 | } 132 | ``` 133 | 134 | #### Logging into account 135 | 136 | Once the user has a valid account, they will need to be logged in to continue. This is handled in the sample app in one of two ways: 137 | 138 | 1. **[Log in to existing account](#logging-into-existing-account)** - Log in to a returning users account. 139 | 140 | ##### Logging into existing account 141 | 142 | After logging out of the app, returning users will want to log into their existing account. Let's take a look at how the Cayenne Sample App and asks the user for their account credentails. We will then examine how the Cayenne Cloud API can be used to log the user into their existing account using the information provided. 143 | 144 |


Sample App Login screen

145 | 146 | The following will go over how to log into an existing account using three methods. 147 | 148 | 1. Logging in using password grant type 149 | This method will use your email and password used when creating your account and will return an `access_token` and `refresh_token` on success. The endpoint used is `https://auth.mydevices.com/oauth/token` with the following payload: 150 | ``` 151 | { 152 | "grant_type": "password", 153 | "email": "YOUR EMAIL", 154 | "password": "YOUR PASSWORD 155 | } 156 | ``` 157 | 158 | Example `POST` curl call: 159 | `curl -X POST -H 'Content-Type: application/json' 'https://auth.mydevices.com/users' -d '{"grant_type": "password", "email": "YOUR EMAIL", "password": "YOUR PASSWORD"}'` 160 | 161 | A successful response will return the following: 162 | ``` 163 | { 164 | "access_token": "YOUR AUTH TOKEN", 165 | "refresh_token": "YOUR REFRESH TOKEN" 166 | } 167 | ``` 168 | 169 | For the following steps, we will be using `http://example.com/redirect` (must be added to your application's redirects) and using the following URL with `response_type` being `code` for explicit or `token` for implicit: 170 | `https://auth.mydevices.com/oauth/authorization?redirect_uri=http%3A%2F%2Fexample.com%2Fredirect&client_id=YOUR APP ID&response_type=TYPE&state=0123456789` 171 | 172 | 2. Logging in using oAuth through implicit flow using `http://example.com/redirect` (the sample app will use `sample://implicit` for implicit flow) 173 | 174 | For implicit, you will use: `https://auth.mydevices.com/oauth/authorization?redirect_uri=http%3A%2F%2Fexample.com%2Fredirect&client_id=YOUR APP ID&response_type=token&state=0123456789` 175 | 176 | You will be taken to a login page when accessing the url and after a successful login, you'll be redirected to `http://example.com/redirect#access_token=YOUR ACCESS TOKEN&state=0123456789`. The access_token is your oAuth token can can be used to access your application's things. For the sample app, you'll be redirected back to your app using deep linking with a redirect of `sample://implicit`. 177 | 178 | 3. Logging in using oAuth through explicit flow. Note: this is added in the sample app for demonstration purposes, it is recommended to use Implicit flow for apps and single page applications. 179 | 180 | For explicit, you will use: `https://auth.mydevices.com/oauth/authorization?redirect_uri=http%3A%2F%2Fexample.com%2Fredirect&client_id=YOUR APP ID&response_type=code&state=0123456789` 181 | 182 | After a successful login, you'll be redirected to `http://example.com/redirect?code=YOUR CODE&state=0123456789` 183 | With the code provided you can make a `POST` to `https://auth.mydevices.com/oauth/token` with the following payload: 184 | ``` 185 | { 186 | "client_id": "YOUR APP KEY", 187 | "client_secret": "YOUR APP SECRET", 188 | "code": "CODE FROM URL", 189 | "grant_type": "authorization_code", 190 | "redirect_uri": "http://example.com/redirect" 191 | } 192 | ``` 193 | 194 | Example curl call: 195 | `curl -X POST 'https://auth.mydevices.com/oauth/token' -d '{ "client_id": "YOUR APP KEY", "client_secret": "YOUR APP SECRET", "code": "CODE FROM URL", "grant_type": "authorization_code", "redirect_uri": "http://example.com/redirect"}'` 196 | 197 | Successful response will return the following: 198 | ``` 199 | { 200 | "acess_token": "YOUR oAUTH TOKEN", 201 | "refresh_token": "YOUR REFRESH TOKEN" 202 | } 203 | ``` 204 | 205 | Within the sample app, you'll also be redirected to your app using deep linking with a redirect of `sample://explicit` and will make a post to `oauth/token` with the returned code. 206 | 207 | #### Reset Password 208 | 209 | In the event that a user has forgotten their password, the Cayenne Cloud API can be used to reset the password. Let's take a look at the Cayenne Sample App and examine how it deals with this scenario. 210 | 211 | **Generate password reset email** 212 | 213 | In order to reset the user's password, we first need to know the users login information. After providing this information, we can use the Cayenne Cloud API to generate and send an email containing a password reset link. 214 | 215 |


Sample App Forgot password screen

216 | 217 |


Sample App Password reset email confirmation

218 | 219 | In order to send a reset password link to your account's email, make a `POST` to `https://auth.mydevices.com/password/forgot` with the following payload: 220 | 221 | ``` 222 | { 223 | "email": "YOUR EMAIL" 224 | } 225 | ``` 226 | 227 | Example curl call: 228 | `curl -X POST 'https://auth.mydevices.com/password/forgot' -d '{"email": "YOUR EMAIL"}'` 229 | 230 | Successful response will return `{ "success": true }`. You will receive an email shortly after the POST. 231 | 232 | #### Device Types 233 | 234 | Before preprovisioning a device, you must first add device types to your application which is done by using the oAuth token in step 2 or 3 of [Logging into existing account](#logging-into-existing-account). 235 | 236 | To add a device type to your application, issue a `POST` to `https://platform.mydevices.com/v1.1/things/types` with the following example gateway payload: 237 | ``` 238 | { 239 | "name": "My Gateway", 240 | "description": "A sample gateway", 241 | "version": "v1.0", 242 | "manufacturer": "Example Inc.", 243 | "parent_constraint": "NOT_ALLOWED", 244 | "child_constraint": "ALLOWED", 245 | "category": "module", 246 | "subcategory": "sample", 247 | "transport_protocol": "someprotocol" 248 | } 249 | ``` 250 | 251 | And with an example sensor payload: 252 | ``` 253 | { 254 | "name": "My Sensor", 255 | "description": "A sample sensor", 256 | "version": "v1.0", 257 | "manufacturer": "Example Inc.", 258 | "parent_constraint": "ALLOWED", 259 | "child_constraint": "ALLOWED", 260 | "category": "sensor", 261 | "subcategory": "sample", 262 | "transport_protocol": "someprotocol" 263 | } 264 | ``` 265 | 266 | Example curl call: 267 | `curl -X POST -H 'Authorization: Bearer OAUTH_TOKEN_HERE' 'https://platform.mydevices.com/v1.1/things/types -d '{"name": "My Gateway", "description": "A sample gateway", "version": "v1.0", "manufacturer": "Example Inc.", "parent_constraint": "NOT_ALLOWED", "child_constraint": "ALLOWED", "category": "module", "subcategory": "sample", "transport_protocol": "someprotocol"}'` 268 | 269 | Succesful response will return the following: 270 | ``` 271 | { 272 | "id": "DEVICE TYPE ID", 273 | "created_at": "2017-08-08T23:51:00.000Z", 274 | "updated_at": "2017-08-08T23:51:00.000Z", 275 | "name": "My Gateway", 276 | "description": "A sample gateway", 277 | "version": "v1.0", 278 | "manufacturer": "Example Inc.", 279 | "parent_constraint": "NOT_ALLOWED", 280 | "child_constraint": "ALLOWED", 281 | "category": "module", 282 | "subcategory": "sample", 283 | "transport_protocol": "someprotocol" 284 | } 285 | ``` 286 | 287 | The "id" value in payload response is your device_type_id which will be used in the next section, [Provisioning Devices](#provisioning-devices). 288 | 289 | You may also view a list of all your device types by issuing a `GET` to `https://platform.mydevices.com/v1.1/things/types` with a header of `Authorization: Bearer OAUTH_TOKEN`. 290 | 291 | #### Provisioning Devices 292 | 293 | Before a device can be activated using the Cayenne Cloud API, it must first be provisioned. Provisioning a device prepares the Cayenne backend to activate the device and generates the **Hardware IDs** that are required during the [Device Activation](#activating-a-device) process. 294 | 295 | Let's provision an example Gateway, Sensor and Actuator which we will continue to use throughout the rest of our examples. The Cayenne Cloud API provides different ways for us to provision these devices. 296 | 297 | - **[Provision devices one at a time](#provision-single-devices)** - How to provision devices one at a time. 298 | - **[Bulk provision the devices](#bulk-provisioning-devices)** - How to provision multiple devices at once. 299 | 300 | ##### Provision single Devices 301 | 302 | Devices can be provisioned one at a time, allowing for tasks such as one-off or on demand provisioning of devices. Let's examine using the Cayenne Cloud API to provision our example devices, one at a time. 303 | 304 | We will be issuing a `POST` to `https://platform.mydevices.com/v1.1/things/registry` with a `Authorization: Bearer OAUTH_TOKEN` header and the following example payload: 305 | 306 | ``` 307 | { 308 | "codec": "some codec", 309 | "hardware_id": "YOUR CHOSEN UNIQUE HARDARE ID", 310 | "device_type_id": "YOUR DEVICE TYPE ID", 311 | "application_id": "YOUR APP KEY", 312 | "response_csv": false 313 | } 314 | ``` 315 | 316 | Example curl call: 317 | ``` 318 | curl --request POST \ 319 | --url https://platform.mydevices.com/v1.1/things/registry \ 320 | --header 'authorization: Bearer_OAUTH TOKEN_HERE' \ 321 | --header 'content-type: application/json' \ 322 | --data '{ 323 | "codec": "some codec", 324 | "hardware_id": "YOUR CHOSEN UNIQUE HARDARE ID", 325 | "device_type_id": "YOUR DEVICE TYPE ID", 326 | "application_id": "YOUR APP KEY", 327 | "response_csv": false 328 | }' 329 | ``` 330 | 331 | Successful response will return the following payload example: 332 | ``` 333 | { 334 | "id": "SOME ID VALUE", 335 | "status": "PENDING", 336 | "created_at": "2017-08-09T00:04:14.000Z", 337 | "codec": "some codec", 338 | "hardware_id": "YOUR CHOSEN UNIQUE HARDARE ID", 339 | "device_type_id": "YOUR DEVICE TYPE ID", 340 | "application_id": "YOUR APP KEY" 341 | } 342 | ``` 343 | 344 | Having done this, you are now able to add a device by using your chosen unique hardware id and this will be explained in [Activating a device](#activating-a-device). 345 | 346 | ##### Bulk Provisioning Devices 347 | 348 | If you have multiple devices that need to be provisioned, the Cayenne Cloud API allows you to batch or bulk provision the devices. Let's provision the same devices as seen in the [Single Device](#provision-single-devices) example, only this time we'll see how they can be provisioned all at once. 349 | 350 | **Note: There is a limit of 500 devices that can be provisioned at a time.** 351 | 352 | We will be issuing a `POST` to `https://platform.mydevices.com/v1.1/things/registry/batch` with a `Authorization: Bearer OAUTH_TOKEN` header and the following example payload: 353 | ``` 354 | { 355 | "device_type_id": "YOUR DEVICE TYPE ID", 356 | "hardware_ids": [ 357 | "HARDWARE ID 1", 358 | "HARDWARE ID 2", 359 | ..., 360 | "HARDWARE ID N" 361 | ], 362 | "count": N, 363 | "response_csv": false 364 | } 365 | ``` 366 | 367 | Example curl call: 368 | ``` 369 | curl --request POST \ 370 | --url https://platform.mydevices.com/v1.1/things/registry/batch \ 371 | --header 'authorization: Bearer YOUR_OAUTH_TOKEN' \ 372 | --header 'content-type: application/json' \ 373 | --data '{ 374 | "device_type_id": "YOUR DEVICE TYPE ID", 375 | "hardware_ids": [ 376 | "HARDWARE ID 1", 377 | "HARDWARE ID 2", 378 | ..., 379 | "HARDWARE ID N" 380 | ], 381 | "count": N, 382 | "response_csv": false 383 | }' 384 | ``` 385 | 386 | Successful response will return the following payload: 387 | ``` 388 | [ 389 | { 390 | "id": "SOME ID VALUE", 391 | "application_id": "APP KEY", 392 | "hardware_id": "HARDARE ID 1", 393 | "device_type_id": "YOUR DEVICE TYPE ID", 394 | "codec": null, 395 | "status": "PENDING", 396 | "created_at": "2017-08-08T18:25:52.000Z" 397 | }, 398 | { 399 | "id": "SOME ID VALUE", 400 | "application_id": "APP KEY", 401 | "hardware_id": "HARDWARE ID 2", 402 | "device_type_id": "YOUR DEVICE TYPE ID", 403 | "codec": null, 404 | "status": "PENDING", 405 | "created_at": "2017-08-08T18:25:52.000Z" 406 | }, 407 | ... 408 | { 409 | "id": "SOME ID VALUE", 410 | "application_id": "APP KEY", 411 | "hardware_id": "HARDWARE ID N", 412 | "device_type_id": "YOUR DEVICE TYPE ID", 413 | "codec": null, 414 | "status": "PENDING", 415 | "created_at": "2017-08-08T18:25:52.000Z" 416 | } 417 | ] 418 | ``` 419 | 420 | #### Activating a Device 421 | 422 | Once a device has been provisioned, it can then be activated and added to the user's account. Let's build upon the [provisioning example](#provisioning-devices) and examine how the user can activate the example devices using the Cayenne Sample App and the Cayenne Cloud API. 423 | 424 | Let's begin by seeing how a Gateway device is activated. After selecting to add a Gateway device, the user is asked for device information needed to activate the gateway. After entering in the information, the Cayenne Cloud API can be used to activate the device. 425 | 426 | *NOTE: Notice how the user is asked for the __Gateway ID__ during the activation process. This ID is the __Hardware ID__ generated earlier during the device provisioning step.* 427 | 428 |


Sample App Add Gateway screen

429 | 430 | To add a gateway using the hardware id, we will issue a `POST` to `https://platform.mydevices.com/v1.1/things/pair` with a `Authorization: Bearer OAUTH_TOKEN` header and the following example payload: 431 | ``` 432 | { 433 | "hardware_id": "YOUR HARDARE ID", 434 | "name": "Sample App Device" 435 | } 436 | ``` 437 | 438 | Example curl call: 439 | ``` 440 | curl --request POST \ 441 | --url https://platform.mydevices.com/v1.1/things/pair \ 442 | --header 'authorization: Bearer OAUTH_TOKEN' \ 443 | --header 'content-type: application/json' \ 444 | --data '{ 445 | "hardware_id": "YOUR HARDARE ID", 446 | "name": "Sample App Device" 447 | }' 448 | ``` 449 | 450 | Successful response will return the following: 451 | ``` 452 | { 453 | "id": "DEVICE ID", 454 | "name": "Sample App Device", 455 | "hardware_id": "HARDWARE ID, 456 | "user_id": "YOUR USER ACCOUNT ID", 457 | "device_type_id": "YOUR DEVICE TYPE ID", 458 | "created_at": "2017-08-03T20:41:57.000Z", 459 | "updated_at": "2017-08-03T20:41:57.000Z", 460 | "last_online": null, 461 | "deactivated_at": null, 462 | "status": "ACTIVATED", 463 | "active": 0, 464 | "parent_id": null, 465 | "search_key": null, 466 | "properties": { 467 | "codec": "CODEC IF APPLICABLE, 468 | "deveui": "HARDWARE ID", 469 | "network": "NETWORK IF APPLICABLE", 470 | "activation": "activated", 471 | "device_registry_id": "YOUR ID ON REGISTRY ADD" 472 | }, 473 | "device_type": { 474 | "id": "DEVICE TYPE ID", 475 | "created_at": "2017-08-08T23:51:00.000Z", 476 | "updated_at": "2017-08-08T23:51:00.000Z", 477 | "name": "My Gateway", 478 | "description": "A sample gateway", 479 | "version": "v1.0", 480 | "manufacturer": "Example Inc.", 481 | "parent_constraint": "NOT_ALLOWED", 482 | "child_constraint": "ALLOWED", 483 | "category": "module", 484 | "subcategory": "sample", 485 | "transport_protocol": "someprotocol" 486 | "model": null, 487 | "protocol_version": null, 488 | "data_type": null, 489 | "proxy_handler": null, 490 | "application_id": "APP KEY" 491 | }, 492 | "key": null, 493 | "client_id": "YOUR CLIENT ID", 494 | "children": [] 495 | } 496 | ``` 497 | 498 | After adding a Gateway device, we can then add sensors and actuators that will communicate with the gateway. Let's activate the sensor and actuator example devices that we previously provisioned. After selecting to add a Device, the user is asked for device information needed to activate the sensor or actuator. After entering in the information, the Cayenne Cloud API can be used to activate the device. 499 | 500 | *NOTE: Notice how the user is asked for the __ID__ during the activation process. This ID is the __Hardware ID__ generated earlier during the device provisioning step.* 501 | 502 |


Sample App Add Sensor screen

503 | 504 |


Sample App Add Sensor screen2

505 | 506 | To add a sensor to a gateway, we will issue a `POST` to `https://platform.mydevices.comv/v1.1/things` with a `Authorization: Bearer OAUTH_TOKEN` header and the following example payload: 507 | ``` 508 | { 509 | "name": "Sensor Name", 510 | "device_type_id": "SENSOR DEVICE TYPE ID", 511 | "parent_id": "ID WHEN ADDING GATEWAY", 512 | "hardware_id": "HARDWARE ID", 513 | "properties": { 514 | "someproperty": "Additional properties can be added here for your sensor", 515 | "deveui": "YOUR HARDARE ID", 516 | "network": "some network if applicable" 517 | }, 518 | "active": 1 519 | "status": "ACTIVATED" 520 | } 521 | ``` 522 | 523 | Sample curl call: 524 | ``` 525 | curl --request GET \ 526 | --url https://platform.mydevices.com/v1.1/things \ 527 | --header 'authorization: Bearer OAUTH_TOKEN' \ 528 | --header 'content-type: application/json' \ 529 | --data '{ 530 | "name": "Sensor Name", 531 | "device_type_id": "SENSOR DEVICE TYPE ID", 532 | "parent_id": "ID WHEN ADDING GATEWAY", 533 | "hardware_id": "HARDWARE ID", 534 | "properties": { 535 | "someproperty": "Additional properties can be added here for your sensor", 536 | "deveui": "YOUR HARDARE ID", 537 | "network": "some network if applicable" 538 | }, 539 | "active": 1 540 | "status": "ACTIVATED" 541 | }' 542 | ``` 543 | 544 | --- 545 | 546 | 547 | #### Getting Real-Time Device Data 548 | 549 | After devices are activated and begin transmitting data to Cayenne, the Cayenne Cloud API can be used to query real-time data on the device. Let's take a look at the Tank Monitoring sample app and see how it uses the Cayenne Cloud API to fetch current device status so that it can be displayed on the *Status* screen. 550 | 551 |


Sample App Status screen

552 | 553 | 554 | #### Remote Control 555 | 556 | In addition to monitoring Sensor devices, the Cayenne Cloud API also supports Actuators. Actuators devices allow you to not only monitor the status of the actuator, but also to remotely control their state. For example, you can remotely lock or unlock a Door Lock, or change the brightness of a Light. The Tank Monitoring sample app includes an example of a Door Lock that we can exmaine. From the *Status* screen we see that there is a toggle shown next to the **Gate Lock** device. The user is able to tap on this button to switch the current lock state of the device. Let's take a look at how this is accomplish using the Cayenne Cloud API. 557 | 558 |


Sample App Device History screen

559 | 560 | 561 | #### Getting Device History 562 | 563 | Cayenne maintains historical information on data received from connected devices. Let's examine using the Cayenne Cloud API to query historical data for our example devices and see some very different examples of how the Tank Monitoring sample app uses this data to display the information to the user. 564 | 565 | ##### Sensor History example 566 | 567 | Tapping on a device from the Tank Monitoring sample app's *Status* screen opens the *Device History* screen which displays historical device data. The user can use this table view to filter and examine data. Let's explore how this is accomplished using the Cayenne Cloud API. 568 | 569 |


Sample App Device History screen

570 | 571 | 572 | ##### Asset Tracking example 573 | 574 | The Tank Monitoring sample app's *Map* screen provides another great example of using historical device data in a unique way. In this case, for display of device location and status on a map. Let's take a look at this *Asset Tracking* feature and how the Cayenne Cloud API is used to accomplish this. 575 | 576 | **Displaying device location on a map** 577 | 578 | On the *Map* screen in the Tank Monitoring sample app, the user can see the location and movement of their devices on a map. This unique presentation makes use of current and historical device information provided in the Cayenne Cloud API to visualize device location data. 579 | 580 |


Sample App rotated map screen

581 | 582 | 583 | **Displaying historical device data on a map** 584 | 585 | In addition to visualizing the location of the device on a map, a user can tap on a device marker to pull up additional information. Within the popup dialog that appears, the historical information on the device is displayed. This allows the Tank Monitoring sample app user to not only see where the device was, but also to see its status at that time. 586 | 587 |


Sample App Map screen

588 | 589 | #### Alerts 590 | 591 | Alerts allow you to receive notifications when certain conditions are met. Let's take a look at the Tank Monitoring sample app and see how the user can create an Alert and manage existing alerts using the Cayenne Cloud API. 592 | 593 | ##### Creating an Alert 594 | 595 | To create a new Alert, the user must specify information on what conditions should be met and who should be notified. After obtaining the information from the user, a new Alert can be created. 596 | 597 |


Sample App create alert screen

598 | 599 | ##### Managing Alerts 600 | 601 | After setting up alerts, users will want to be able to manage them. Let's take a look at the Tank Monitoring sample app's *Alerts* screen. From this screen the user can see a list of existing alerts, information on each alert, and they can manage the alerts. Let's see how these tasks are accomplished using the Cayenne Cloud API. 602 | 603 |


Sample App Alerts screen

604 | 605 | #### Multi-Tenant 606 | 607 | In addition to manging Accounts and Devices, the Cayenne Cloud API also provides functionality to help create and manage Users. Using the Multi-Tenant features found in the Cayenne Cloud API, you can create Users and assign Roles and permissions. Let's take a look at an example which demonstrates these features. 608 | 609 | ##### Creating Users, assigning Roles & Permissions 610 | 611 | Before you can manage users and assign permission, a new User must be created. As an example, this can be done from an *Add User* screen. In order to get started with creating a new user, we must first get some basic information on the user. 612 | 613 |


Multi tenant Add User 1

614 | 615 | After capturing the basic user information, we then select the **Role** and **Permissions** available to the user. By adjusting the user's role and permissions, we can control what access the user has within the account. Setting the user's **Role** will determine certain default **Permissions** available. If you want, you can override the default permissions by specifying what the user should have on a per-feature basis. 616 | 617 | - **View:** Allows the User to view this feature. Without this permission, the feature will not be visible to the user. 618 | - **Add/Edit:** Allows the User to modify items within this feature. For example, to Add device or Edit/Update information. 619 | - **Delete:** Allows the User to delete items within this feature. For example, to remove devices. 620 | 621 |


Multi tenant Add User 2

622 | 623 | After gathering the information required to create a new User, we can then use the Cayenne Cloud API to create a new user. Let's examine how this is accomplished. 624 | 625 | 626 | ##### Managing existing users 627 | 628 | After creating some Users, we need to be able to manage them. Let’s take a look at an example *Users* screen. From this screen you can see a list of existing users and we can manage the existing user from here. Let's see how these tasks are accomplished using the Cayenne Cloud API. 629 | 630 |


Multi tenant manage Users screen

631 | -------------------------------------------------------------------------------- /__tests__/index.android.js: -------------------------------------------------------------------------------- 1 | import 'react-native'; 2 | import React from 'react'; 3 | import Index from '../index.android.js'; 4 | 5 | // Note: test renderer must be required after react-native. 6 | import renderer from 'react-test-renderer'; 7 | 8 | it('renders correctly', () => { 9 | const tree = renderer.create( 10 | 11 | ); 12 | }); 13 | -------------------------------------------------------------------------------- /__tests__/index.ios.js: -------------------------------------------------------------------------------- 1 | import 'react-native'; 2 | import React from 'react'; 3 | import Index from '../index.ios.js'; 4 | 5 | // Note: test renderer must be required after react-native. 6 | import renderer from 'react-test-renderer'; 7 | 8 | it('renders correctly', () => { 9 | const tree = renderer.create( 10 | 11 | ); 12 | }); 13 | -------------------------------------------------------------------------------- /android/app/BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | lib_deps = [] 12 | 13 | for jarfile in glob(['libs/*.jar']): 14 | name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')] 15 | lib_deps.append(':' + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | 21 | for aarfile in glob(['libs/*.aar']): 22 | name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')] 23 | lib_deps.append(':' + name) 24 | android_prebuilt_aar( 25 | name = name, 26 | aar = aarfile, 27 | ) 28 | 29 | android_library( 30 | name = "all-libs", 31 | exported_deps = lib_deps, 32 | ) 33 | 34 | android_library( 35 | name = "app-code", 36 | srcs = glob([ 37 | "src/main/java/**/*.java", 38 | ]), 39 | deps = [ 40 | ":all-libs", 41 | ":build_config", 42 | ":res", 43 | ], 44 | ) 45 | 46 | android_build_config( 47 | name = "build_config", 48 | package = "com.cayennesampleapp", 49 | ) 50 | 51 | android_resource( 52 | name = "res", 53 | package = "com.cayennesampleapp", 54 | res = "src/main/res", 55 | ) 56 | 57 | android_binary( 58 | name = "app", 59 | keystore = "//android/keystores:debug", 60 | manifest = "src/main/AndroidManifest.xml", 61 | package_type = "debug", 62 | deps = [ 63 | ":app-code", 64 | ], 65 | ) 66 | -------------------------------------------------------------------------------- /android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" 2 | 3 | apply plugin: "com.android.application" 4 | 5 | import com.android.build.OutputFile 6 | 7 | /** 8 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 9 | * and bundleReleaseJsAndAssets). 10 | * These basically call `react-native bundle` with the correct arguments during the Android build 11 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 12 | * bundle directly from the development server. Below you can see all the possible configurations 13 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 14 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 15 | * 16 | * project.ext.react = [ 17 | * // the name of the generated asset file containing your JS bundle 18 | * bundleAssetName: "index.android.bundle", 19 | * 20 | * // the entry file for bundle generation 21 | * entryFile: "index.android.js", 22 | * 23 | * // whether to bundle JS and assets in debug mode 24 | * bundleInDebug: false, 25 | * 26 | * // whether to bundle JS and assets in release mode 27 | * bundleInRelease: true, 28 | * 29 | * // whether to bundle JS and assets in another build variant (if configured). 30 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 31 | * // The configuration property can be in the following formats 32 | * // 'bundleIn${productFlavor}${buildType}' 33 | * // 'bundleIn${buildType}' 34 | * // bundleInFreeDebug: true, 35 | * // bundleInPaidRelease: true, 36 | * // bundleInBeta: true, 37 | * 38 | * // the root of your project, i.e. where "package.json" lives 39 | * root: "../../", 40 | * 41 | * // where to put the JS bundle asset in debug mode 42 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 43 | * 44 | * // where to put the JS bundle asset in release mode 45 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 46 | * 47 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 48 | * // require('./image.png')), in debug mode 49 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 50 | * 51 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 52 | * // require('./image.png')), in release mode 53 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 54 | * 55 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 56 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 57 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 58 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 59 | * // for example, you might want to remove it from here. 60 | * inputExcludes: ["android/**", "ios/**"], 61 | * 62 | * // override which node gets called and with what additional arguments 63 | * nodeExecutableAndArgs: ["node"], 64 | * 65 | * // supply additional arguments to the packager 66 | * extraPackagerArgs: [] 67 | * ] 68 | */ 69 | 70 | apply from: "../../node_modules/react-native/react.gradle" 71 | 72 | /** 73 | * Set this to true to create two separate APKs instead of one: 74 | * - An APK that only works on ARM devices 75 | * - An APK that only works on x86 devices 76 | * The advantage is the size of the APK is reduced by about 4MB. 77 | * Upload all the APKs to the Play Store and people will download 78 | * the correct one based on the CPU architecture of their device. 79 | */ 80 | def enableSeparateBuildPerCPUArchitecture = false 81 | 82 | /** 83 | * Run Proguard to shrink the Java bytecode in release builds. 84 | */ 85 | def enableProguardInReleaseBuilds = false 86 | 87 | android { 88 | compileSdkVersion 23 89 | buildToolsVersion "23.0.1" 90 | 91 | defaultConfig { 92 | applicationId "com.cayennesampleapp" 93 | minSdkVersion 16 94 | targetSdkVersion 22 95 | versionCode 1 96 | versionName "1.0" 97 | ndk { 98 | abiFilters "armeabi-v7a", "x86" 99 | } 100 | } 101 | splits { 102 | abi { 103 | reset() 104 | enable enableSeparateBuildPerCPUArchitecture 105 | universalApk false // If true, also generate a universal APK 106 | include "armeabi-v7a", "x86" 107 | } 108 | } 109 | buildTypes { 110 | release { 111 | minifyEnabled enableProguardInReleaseBuilds 112 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 113 | } 114 | } 115 | // applicationVariants are e.g. debug, release 116 | applicationVariants.all { variant -> 117 | variant.outputs.each { output -> 118 | // For each separate APK per architecture, set a unique version code as described here: 119 | // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits 120 | def versionCodes = ["armeabi-v7a":1, "x86":2] 121 | def abi = output.getFilter(OutputFile.ABI) 122 | if (abi != null) { // null for the universal-debug, universal-release variants 123 | output.versionCodeOverride = 124 | versionCodes.get(abi) * 1048576 + defaultConfig.versionCode 125 | } 126 | } 127 | } 128 | } 129 | 130 | dependencies { 131 | compile fileTree(dir: "libs", include: ["*.jar"]) 132 | compile "com.android.support:appcompat-v7:23.0.1" 133 | compile "com.facebook.react:react-native:+" // From node_modules 134 | } 135 | 136 | // Run this once to be able to run the application with BUCK 137 | // puts all compile dependencies into folder libs for BUCK to use 138 | task copyDownloadableDepsToLibs(type: Copy) { 139 | from configurations.compile 140 | into 'libs' 141 | } 142 | -------------------------------------------------------------------------------- /android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Disabling obfuscation is useful if you collect stack traces from production crashes 20 | # (unless you are using a system that supports de-obfuscate the stack traces). 21 | -dontobfuscate 22 | 23 | # React Native 24 | 25 | # Keep our interfaces so they can be used by other ProGuard rules. 26 | # See http://sourceforge.net/p/proguard/bugs/466/ 27 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip 28 | -keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters 29 | -keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip 30 | 31 | # Do not strip any method/class that is annotated with @DoNotStrip 32 | -keep @com.facebook.proguard.annotations.DoNotStrip class * 33 | -keep @com.facebook.common.internal.DoNotStrip class * 34 | -keepclassmembers class * { 35 | @com.facebook.proguard.annotations.DoNotStrip *; 36 | @com.facebook.common.internal.DoNotStrip *; 37 | } 38 | 39 | -keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * { 40 | void set*(***); 41 | *** get*(); 42 | } 43 | 44 | -keep class * extends com.facebook.react.bridge.JavaScriptModule { *; } 45 | -keep class * extends com.facebook.react.bridge.NativeModule { *; } 46 | -keepclassmembers,includedescriptorclasses class * { native ; } 47 | -keepclassmembers class * { @com.facebook.react.uimanager.UIProp ; } 48 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp ; } 49 | -keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup ; } 50 | 51 | -dontwarn com.facebook.react.** 52 | 53 | # TextLayoutBuilder uses a non-public Android constructor within StaticLayout. 54 | # See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details. 55 | -dontwarn android.text.StaticLayout 56 | 57 | # okhttp 58 | 59 | -keepattributes Signature 60 | -keepattributes *Annotation* 61 | -keep class okhttp3.** { *; } 62 | -keep interface okhttp3.** { *; } 63 | -dontwarn okhttp3.** 64 | 65 | # okio 66 | 67 | -keep class sun.misc.Unsafe { *; } 68 | -dontwarn java.nio.file.* 69 | -dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 70 | -dontwarn okio.** 71 | -------------------------------------------------------------------------------- /android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 12 | 13 | 19 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /android/app/src/main/assets/fonts/Entypo.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/assets/fonts/Entypo.ttf -------------------------------------------------------------------------------- /android/app/src/main/assets/fonts/EvilIcons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/assets/fonts/EvilIcons.ttf -------------------------------------------------------------------------------- /android/app/src/main/assets/fonts/FontAwesome.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/assets/fonts/FontAwesome.ttf -------------------------------------------------------------------------------- /android/app/src/main/assets/fonts/Foundation.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/assets/fonts/Foundation.ttf -------------------------------------------------------------------------------- /android/app/src/main/assets/fonts/Ionicons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/assets/fonts/Ionicons.ttf -------------------------------------------------------------------------------- /android/app/src/main/assets/fonts/MaterialCommunityIcons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/assets/fonts/MaterialCommunityIcons.ttf -------------------------------------------------------------------------------- /android/app/src/main/assets/fonts/MaterialIcons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/assets/fonts/MaterialIcons.ttf -------------------------------------------------------------------------------- /android/app/src/main/assets/fonts/Octicons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/assets/fonts/Octicons.ttf -------------------------------------------------------------------------------- /android/app/src/main/assets/fonts/SimpleLineIcons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/assets/fonts/SimpleLineIcons.ttf -------------------------------------------------------------------------------- /android/app/src/main/assets/fonts/Zocial.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/assets/fonts/Zocial.ttf -------------------------------------------------------------------------------- /android/app/src/main/assets/fonts/fontello.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/assets/fonts/fontello.ttf -------------------------------------------------------------------------------- /android/app/src/main/assets/fonts/icons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/assets/fonts/icons.ttf -------------------------------------------------------------------------------- /android/app/src/main/java/com/cayennesampleapp/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.cayennesampleapp; 2 | 3 | import com.facebook.react.ReactActivity; 4 | 5 | public class MainActivity extends ReactActivity { 6 | 7 | /** 8 | * Returns the name of the main component registered from JavaScript. 9 | * This is used to schedule rendering of the component. 10 | */ 11 | @Override 12 | protected String getMainComponentName() { 13 | return "CayenneSampleApp"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /android/app/src/main/java/com/cayennesampleapp/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.cayennesampleapp; 2 | 3 | import android.app.Application; 4 | 5 | import com.facebook.react.ReactApplication; 6 | import com.facebook.react.ReactNativeHost; 7 | import com.facebook.react.ReactPackage; 8 | import com.facebook.react.shell.MainReactPackage; 9 | import com.facebook.soloader.SoLoader; 10 | 11 | import java.util.Arrays; 12 | import java.util.List; 13 | 14 | public class MainApplication extends Application implements ReactApplication { 15 | 16 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 17 | @Override 18 | public boolean getUseDeveloperSupport() { 19 | return BuildConfig.DEBUG; 20 | } 21 | 22 | @Override 23 | protected List getPackages() { 24 | return Arrays.asList( 25 | new MainReactPackage() 26 | ); 27 | } 28 | }; 29 | 30 | @Override 31 | public ReactNativeHost getReactNativeHost() { 32 | return mReactNativeHost; 33 | } 34 | 35 | @Override 36 | public void onCreate() { 37 | super.onCreate(); 38 | SoLoader.init(this, /* native exopackage */ false); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CayenneSampleApp 3 | 4 | -------------------------------------------------------------------------------- /android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | } 7 | dependencies { 8 | classpath 'com.android.tools.build:gradle:2.2.3' 9 | 10 | // NOTE: Do not place your application dependencies here; they belong 11 | // in the individual module build.gradle files 12 | } 13 | } 14 | 15 | allprojects { 16 | repositories { 17 | mavenLocal() 18 | jcenter() 19 | maven { 20 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 21 | url "$rootDir/../node_modules/react-native/android" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | android.useDeprecatedNdk=true 21 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 6 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /android/keystores/BUCK: -------------------------------------------------------------------------------- 1 | keystore( 2 | name = "debug", 3 | properties = "debug.keystore.properties", 4 | store = "debug.keystore", 5 | visibility = [ 6 | "PUBLIC", 7 | ], 8 | ) 9 | -------------------------------------------------------------------------------- /android/keystores/debug.keystore.properties: -------------------------------------------------------------------------------- 1 | key.store=debug.keystore 2 | key.alias=androiddebugkey 3 | key.store.password=android 4 | key.alias.password=android 5 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'CayenneSampleApp' 2 | include ':react-native-vector-icons' 3 | project(':react-native-vector-icons').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-vector-icons/android') 4 | 5 | include ':app' 6 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import NavigatorService from './js/lib/navigation.service'; 3 | import ROUTES from './js/routes/router'; 4 | 5 | class App extends Component { 6 | render(){ 7 | return ( { 9 | NavigatorService.setContainer(navigatorRef); 10 | }} 11 | />); 12 | } 13 | } 14 | 15 | module.exports = App; -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CayenneSampleApp", 3 | "displayName": "CayenneSampleApp" 4 | } -------------------------------------------------------------------------------- /index.android.js: -------------------------------------------------------------------------------- 1 | import { 2 | AppRegistry 3 | } from 'react-native'; 4 | import App from './app'; 5 | //import NavigatorService from './js/lib/navigation.service'; 6 | 7 | AppRegistry.registerComponent( 8 | 'CayenneSampleApp', 9 | () => App 10 | ); 11 | -------------------------------------------------------------------------------- /index.ios.js: -------------------------------------------------------------------------------- 1 | import { 2 | AppRegistry 3 | } from 'react-native'; 4 | import App from './app'; 5 | //import NavigatorService from './js/lib/navigation.service'; 6 | 7 | AppRegistry.registerComponent( 8 | 'CayenneSampleApp', 9 | () => App 10 | ); 11 | -------------------------------------------------------------------------------- /ios/CayenneSampleApp-tvOS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UIViewControllerBasedStatusBarAppearance 38 | 39 | NSLocationWhenInUseUsageDescription 40 | 41 | NSAppTransportSecurity 42 | 43 | 44 | NSExceptionDomains 45 | 46 | localhost 47 | 48 | NSExceptionAllowsInsecureHTTPLoads 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /ios/CayenneSampleApp-tvOSTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ios/CayenneSampleApp.xcodeproj/xcshareddata/xcschemes/CayenneSampleApp-tvOS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 52 | 53 | 58 | 59 | 61 | 67 | 68 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 92 | 94 | 100 | 101 | 102 | 103 | 104 | 105 | 111 | 113 | 119 | 120 | 121 | 122 | 124 | 125 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /ios/CayenneSampleApp.xcodeproj/xcshareddata/xcschemes/CayenneSampleApp.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 52 | 53 | 58 | 59 | 61 | 67 | 68 | 69 | 70 | 71 | 77 | 78 | 79 | 80 | 81 | 82 | 92 | 94 | 100 | 101 | 102 | 103 | 104 | 105 | 111 | 113 | 119 | 120 | 121 | 122 | 124 | 125 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /ios/CayenneSampleApp/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (nonatomic, strong) UIWindow *window; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /ios/CayenneSampleApp/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import "AppDelegate.h" 11 | 12 | #import 13 | #import 14 | #import 15 | 16 | @implementation AppDelegate 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 19 | { 20 | NSURL *jsCodeLocation; 21 | 22 | jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; 23 | 24 | RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation 25 | moduleName:@"CayenneSampleApp" 26 | initialProperties:nil 27 | launchOptions:launchOptions]; 28 | rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1]; 29 | 30 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 31 | UIViewController *rootViewController = [UIViewController new]; 32 | rootViewController.view = rootView; 33 | self.window.rootViewController = rootViewController; 34 | [self.window makeKeyAndVisible]; 35 | return YES; 36 | } 37 | 38 | //deprecated in iOS 9, weird why it would still have this? 39 | - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { 40 | return [RCTLinkingManager application:application openURL:url 41 | sourceApplication:sourceApplication annotation:annotation]; 42 | } 43 | 44 | - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler { 45 | return [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /ios/CayenneSampleApp/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /ios/CayenneSampleApp/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /ios/CayenneSampleApp/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleURLTypes 6 | 7 | 8 | CFBundleURLSchemes 9 | 10 | sample 11 | 12 | 13 | 14 | UIAppFonts 15 | 16 | fontello.ttf 17 | FontAwesome.ttf 18 | 19 | CFBundleDevelopmentRegion 20 | en 21 | CFBundleDisplayName 22 | CayenneSampleApp 23 | CFBundleExecutable 24 | $(EXECUTABLE_NAME) 25 | CFBundleIdentifier 26 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 27 | CFBundleInfoDictionaryVersion 28 | 6.0 29 | CFBundleName 30 | $(PRODUCT_NAME) 31 | CFBundlePackageType 32 | APPL 33 | CFBundleShortVersionString 34 | 1.0 35 | CFBundleSignature 36 | ???? 37 | CFBundleVersion 38 | 1 39 | LSRequiresIPhoneOS 40 | 41 | UILaunchStoryboardName 42 | LaunchScreen 43 | UIRequiredDeviceCapabilities 44 | 45 | armv7 46 | 47 | UISupportedInterfaceOrientations 48 | 49 | UIInterfaceOrientationPortrait 50 | UIInterfaceOrientationLandscapeLeft 51 | UIInterfaceOrientationLandscapeRight 52 | 53 | UIViewControllerBasedStatusBarAppearance 54 | 55 | NSLocationWhenInUseUsageDescription 56 | 57 | NSAppTransportSecurity 58 | 59 | NSAllowsArbitraryLoads 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /ios/CayenneSampleApp/main.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | 12 | #import "AppDelegate.h" 13 | 14 | int main(int argc, char * argv[]) { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ios/CayenneSampleAppTests/CayenneSampleAppTests.m: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015-present, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under the BSD-style license found in the 6 | * LICENSE file in the root directory of this source tree. An additional grant 7 | * of patent rights can be found in the PATENTS file in the same directory. 8 | */ 9 | 10 | #import 11 | #import 12 | 13 | #import 14 | #import 15 | 16 | #define TIMEOUT_SECONDS 600 17 | #define TEXT_TO_LOOK_FOR @"Welcome to React Native!" 18 | 19 | @interface CayenneSampleAppTests : XCTestCase 20 | 21 | @end 22 | 23 | @implementation CayenneSampleAppTests 24 | 25 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test 26 | { 27 | if (test(view)) { 28 | return YES; 29 | } 30 | for (UIView *subview in [view subviews]) { 31 | if ([self findSubviewInView:subview matching:test]) { 32 | return YES; 33 | } 34 | } 35 | return NO; 36 | } 37 | 38 | - (void)testRendersWelcomeScreen 39 | { 40 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 41 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 42 | BOOL foundElement = NO; 43 | 44 | __block NSString *redboxError = nil; 45 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 46 | if (level >= RCTLogLevelError) { 47 | redboxError = message; 48 | } 49 | }); 50 | 51 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 52 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 53 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 54 | 55 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { 56 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 57 | return YES; 58 | } 59 | return NO; 60 | }]; 61 | } 62 | 63 | RCTSetLogFunction(RCTDefaultLogFunction); 64 | 65 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 66 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 67 | } 68 | 69 | 70 | @end 71 | -------------------------------------------------------------------------------- /ios/CayenneSampleAppTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /js/components/Button/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | Text, 4 | TouchableOpacity 5 | } from 'react-native'; 6 | 7 | import styles from './styles'; 8 | 9 | function Button(props) { 10 | return ( 11 | 16 | 17 | {props.children} 18 | 19 | ); 20 | } 21 | 22 | export default Button; 23 | -------------------------------------------------------------------------------- /js/components/Button/styles.js: -------------------------------------------------------------------------------- 1 | import { 2 | StyleSheet 3 | } from 'react-native'; 4 | 5 | module.exports = StyleSheet.create({ 6 | buttonText:{ 7 | marginLeft:10, 8 | marginRight:10, 9 | marginTop:5, 10 | marginBottom:2, 11 | padding:15, 12 | borderRadius: 5, 13 | textAlign:'center', 14 | backgroundColor: '#2C95EC', 15 | fontSize:24, 16 | color:'white' 17 | } 18 | }) 19 | -------------------------------------------------------------------------------- /js/components/Device/index.js: -------------------------------------------------------------------------------- 1 | import React, { 2 | Component 3 | } from 'react'; 4 | 5 | import { 6 | View, 7 | Text, 8 | TouchableOpacity 9 | } from 'react-native'; 10 | 11 | import Sensor from './../Sensor/index'; 12 | import HistoryService from './../../lib/history.service'; 13 | 14 | class Device extends Component{ 15 | 16 | constructor(props){ 17 | super(props); 18 | this.state = {expanded: false }; 19 | } 20 | 21 | toggleExpand(){ 22 | this.setState({expanded: !this.state.expanded}); 23 | }; 24 | 25 | renderSensors(){ 26 | HistoryService.getState(this.props.device.id); 27 | var deviceId = this.props.device.id; 28 | var sensorList = this.props.sensors.map(function(sensor, i) { 29 | return ( 30 | 31 | ); 32 | }); 33 | return sensorList; 34 | }; 35 | 36 | render() { 37 | return ( 38 | 39 | 40 | 41 | {this.props.device.name} 42 | 43 | 44 | LEVEL: 45 | {/*35%*/} 46 | 47 | 48 | SIGNAL: 49 | {/* 90%*/} 50 | 51 | 52 | BATTERY: 53 | {/* 87%*/} 54 | 55 | 56 | { 57 | this.state.expanded ? 58 | 59 | {this.renderSensors()} 60 | 61 | : null 62 | } 63 | 64 | ); 65 | } 66 | } 67 | 68 | export default Device; 69 | -------------------------------------------------------------------------------- /js/components/Footer/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | Text, 4 | View, 5 | TouchableHighlight 6 | } from 'react-native'; 7 | import { 8 | StackNavigator 9 | } from 'react-navigation'; 10 | import Icon from 'react-native-vector-icons/FontAwesome'; 11 | 12 | function Footer(props) { 13 | const {navigate} = props.navigation; 14 | return ( 15 | 16 | navigate('Status')} style={{flex:0.33}}> 17 | 18 | 19 | STATUS 20 | 21 | 22 | 23 | navigate('SensorMap')} style={{flex:0.33}}> 24 | 25 | 26 | MAP 27 | 28 | 29 | 30 | navigate('Alerts')} style={{flex:0.33}}> 31 | 32 | 33 | ALERTS 34 | 35 | 36 | 37 | ); 38 | } 39 | 40 | export default Footer; 41 | -------------------------------------------------------------------------------- /js/components/Header/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | Text, 4 | View, 5 | TouchableHighlight 6 | } from 'react-native'; 7 | import { 8 | CommonStyles 9 | } from './../index'; 10 | import Icon from 'react-native-vector-icons/FontAwesome'; 11 | 12 | import StorageService from '../../lib/storage.service'; 13 | import NavigationService from '../../lib/navigation.service'; 14 | 15 | function getPlus(isVisible, navigate) { 16 | if (isVisible) { 17 | return ( 18 | 19 | ); 20 | } 21 | } 22 | 23 | function logOut(){ 24 | StorageService.remove('access_token'); 25 | NavigationService.navigate('CreateName'); 26 | } 27 | 28 | function Header(props) { 29 | return ( 30 | 31 | 32 | {/* */} 33 | Log out 34 | 35 | 36 | {props.title} 37 | 38 | 39 | {getPlus(props.visible, props.onPress)} 40 | 41 | 42 | ); 43 | } 44 | 45 | export default Header; 46 | -------------------------------------------------------------------------------- /js/components/Instruction/index.js: -------------------------------------------------------------------------------- 1 | import { 2 | Text, 3 | View, 4 | Image, 5 | } from 'react-native'; 6 | import { 7 | Images 8 | } from './../../config/index'; 9 | import Hr from 'react-native-hr'; 10 | import React from 'react'; 11 | import Icon from 'react-native-vector-icons/FontAwesome'; 12 | 13 | function Instructions(props) { 14 | if (!props.show) { 15 | return ( 16 | 17 | 21 | {props.title} 27 | 28 | 30 | View Instructions 31 | 32 | 33 |
34 |
35 | ); 36 | } 37 | return ( 38 | 39 | 43 | {props.title} 49 | 50 | 52 | Hide Instructions 53 | 54 | 55 | 56 | 61 | 65 | {props.instructions[0]} 66 |
67 | 71 | {props.instructions[1]} 72 |
73 |
74 | 75 |
76 | ); 77 | } 78 | 79 | export default Instructions; 80 | -------------------------------------------------------------------------------- /js/components/ModalBox/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | Text, 4 | Modal, 5 | View 6 | } from 'react-native'; 7 | 8 | import STYLES from '../common-styles'; 9 | import TouchButton from '../Button/index'; 10 | 11 | function ModalBox(props) { 12 | return ( 13 | 19 | 20 | 21 | 22 | 23 | {props.modalText} 24 | 28 | {props.buttonText} 29 | 30 | 31 | 32 | 33 | 34 | 35 | ); 36 | } 37 | 38 | export default ModalBox; 39 | -------------------------------------------------------------------------------- /js/components/Sensor/index.js: -------------------------------------------------------------------------------- 1 | import React, { 2 | Component 3 | } from 'react'; 4 | 5 | import { 6 | View, 7 | Text 8 | } from 'react-native'; 9 | 10 | import StreamingService from './../../lib/streaming.service'; 11 | 12 | class Sensor extends Component{ 13 | 14 | constructor(props){ 15 | super(props); 16 | this.state ={value: null}; 17 | this.subscriberId = null; 18 | } 19 | 20 | componentWillMount() { 21 | // Listen for event 22 | this.subscriberId = StreamingService.getInstance().subscribe( 23 | 'data-changed',this.props.deviceId, this.props.sensor.properties.channel, 24 | this.update.bind(this) 25 | ); 26 | } 27 | 28 | componentWillUnmount(){ 29 | // unsubscribe for event 30 | StreamingService.getInstance().unsubscribe( 31 | 'data-changed', this.props.deviceId, this.props.sensor.properties.channel, 32 | this.subscriberId 33 | ); 34 | } 35 | 36 | update(value){ 37 | this.setState({value: value}); 38 | } 39 | 40 | render(){ 41 | return ( 42 | 43 | 44 | {this.props.sensor.name} 45 | 46 | 47 | 48 | {this.state.value === null ? 49 | '' : this.state.value.value 50 | } 51 | 52 | 53 | 54 | 55 | {this.state.value === null ? 56 | '' : this.state.value.label 57 | } 58 | 59 | 60 | 61 | ); 62 | } 63 | } 64 | 65 | export default Sensor; -------------------------------------------------------------------------------- /js/components/TextBox/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | TextInput, 4 | } from 'react-native'; 5 | 6 | import styles from './styles'; 7 | 8 | function TextBox(props) { 9 | return ( 10 | 17 | ); 18 | } 19 | 20 | export default TextBox; 21 | -------------------------------------------------------------------------------- /js/components/TextBox/styles.js: -------------------------------------------------------------------------------- 1 | import { 2 | StyleSheet 3 | } from 'react-native'; 4 | 5 | module.exports = StyleSheet.create({ 6 | inputField: { 7 | marginLeft:10, 8 | marginRight:10, 9 | marginTop:5, 10 | marginBottom:5, 11 | padding:15, 12 | borderRadius: 5, 13 | backgroundColor:'white' 14 | } 15 | }) 16 | -------------------------------------------------------------------------------- /js/components/common-styles.js: -------------------------------------------------------------------------------- 1 | import { 2 | StyleSheet 3 | } from 'react-native'; 4 | 5 | export default StyleSheet.create({ 6 | inputField: { 7 | marginLeft:10, 8 | marginRight:10, 9 | marginTop:5, 10 | marginBottom:5, 11 | padding:15, 12 | borderRadius: 5, 13 | backgroundColor:'white' 14 | }, 15 | picker: { 16 | marginLeft:10, 17 | marginRight:10, 18 | marginTop:5, 19 | marginBottom:5, 20 | padding:15, 21 | borderRadius: 5, 22 | backgroundColor:'white' 23 | }, 24 | linkText: { 25 | marginTop:1, 26 | padding:1, 27 | textAlign:'center', 28 | backgroundColor: 'transparent', 29 | fontSize:16, 30 | color:'white', 31 | textDecorationLine:'underline', 32 | textDecorationStyle:'solid' 33 | }, 34 | backgroundImageContainer:{ 35 | flex: 1, 36 | resizeMode:'stretch', 37 | width: undefined, 38 | height: undefined, 39 | backgroundColor: 'transparent', 40 | justifyContent: 'center' 41 | }, 42 | modalText:{ 43 | marginLeft:10, 44 | marginRight:10, 45 | marginTop:5, 46 | marginBottom:2, 47 | padding:15, 48 | textAlign:'center', 49 | fontSize:18, 50 | color:'black' 51 | }, 52 | screenText: { 53 | color: '#FFFFFF', 54 | textAlign: 'center', 55 | fontSize: 16, 56 | marginBottom: 5, 57 | marginTop: 5, 58 | width: 250 59 | }, 60 | background: { 61 | flex: 1, 62 | width: undefined, 63 | height: undefined, 64 | backgroundColor: '#3A4950', 65 | }, 66 | textHeader: { 67 | width: 100, 68 | textAlign: 'center' 69 | }, 70 | white: { 71 | color: '#FFFFFF' 72 | }, 73 | 74 | 75 | 76 | sensorBackground: { 77 | flex: 1, 78 | width: undefined, 79 | height: undefined, 80 | backgroundColor: '#000050', 81 | }, 82 | }) 83 | -------------------------------------------------------------------------------- /js/components/index.js: -------------------------------------------------------------------------------- 1 | import TouchButton from './Button/index'; 2 | import TextBox from './TextBox/index'; 3 | import ModalBox from './ModalBox/index'; 4 | import CommonStyles from './common-styles'; 5 | import Instructions from './Instruction/index'; 6 | import Footer from './Footer/index'; 7 | import Header from './Header/index'; 8 | import Device from './Device/index'; 9 | 10 | export { TouchButton }; 11 | export { TextBox }; 12 | export { ModalBox }; 13 | export { CommonStyles }; 14 | export { Instructions }; 15 | export { Footer }; 16 | export { Header }; 17 | export { Device }; 18 | -------------------------------------------------------------------------------- /js/config/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "css_prefix_text": "icon-", 4 | "css_use_suffix": false, 5 | "hinting": true, 6 | "units_per_em": 1000, 7 | "ascent": 850, 8 | "glyphs": [ 9 | { 10 | "uid": "6ed131d28328b048a6a6e27ad2613250", 11 | "css": "cayenne", 12 | "code": 59501, 13 | "src": "custom_icons", 14 | "selected": true, 15 | "svg": { 16 | "path": "M445 501C445 449 487 407 539 407 591 407 633 449 633 501 633 553 591 595 539 595 487 595 445 553 445 501M83 500C83 247 287 42 536 42 672 42 800 103 887 211 933 268 925 352 869 398 812 444 730 436 684 379 646 333 594 307 536 307 431 307 346 394 346 500 346 606 431 693 536 693 594 693 646 667 684 621 730 564 812 555 869 602 925 648 933 732 887 789 800 896 672 958 536 958 286 958 83 753 83 500", 17 | "width": 1000 18 | }, 19 | "search": [ 20 | "cayenne" 21 | ] 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /js/config/images.js: -------------------------------------------------------------------------------- 1 | const images = { 2 | loginSplash: require('../images/mydevices.png'), 3 | logo: require('../images/myDevicesWhite.png'), 4 | gatewaySetup: require('./../images/graphic-gateway-setup.png'), 5 | gatewayPlacement: require('./../images/graphic-gateway-placement.png'), 6 | elsysSensor: require('./../images/graphic-setup-elsys.png') 7 | } 8 | 9 | export default images; 10 | -------------------------------------------------------------------------------- /js/config/index.js: -------------------------------------------------------------------------------- 1 | import Images from './images'; 2 | import Session from './session'; 3 | import Settings from './settings'; 4 | 5 | export { Images }; 6 | export { Session }; 7 | export { Settings }; 8 | -------------------------------------------------------------------------------- /js/config/session.js: -------------------------------------------------------------------------------- 1 | var session = { 2 | access_token: '', 3 | refresh_token: '', 4 | mqqt_id: '', 5 | mqqt_secret: '' 6 | } 7 | 8 | export default session; 9 | -------------------------------------------------------------------------------- /js/config/settings.js: -------------------------------------------------------------------------------- 1 | // Manually edit this file when making changes to .env 2 | import { 3 | APP_KEY, 4 | APP_SECRET, 5 | AUTH_HOST, 6 | API_HOST, 7 | STREAMING_HOST, 8 | HISTORY_HOST, 9 | RULES_HOST 10 | } from 'react-native-dotenv'; 11 | 12 | const settings = { 13 | appKey: APP_KEY, 14 | appSecret: APP_SECRET, 15 | authHost: AUTH_HOST, 16 | guid: guid, 17 | apiHost: API_HOST, 18 | streamingHost: STREAMING_HOST, 19 | historyHost: HISTORY_HOST, 20 | rulesHost: RULES_HOST 21 | } 22 | 23 | /** 24 | * Create a random GUID 25 | */ 26 | function guid() { 27 | function s4() { 28 | return Math.floor((1 + Math.random()) * 0x10000) 29 | .toString(16) 30 | .substring(1); 31 | } 32 | return s4() + s4() + '-' + s4() + '-' + s4() + '-' + 33 | s4() + '-' + s4() + s4() + s4(); 34 | } 35 | 36 | 37 | export default settings; 38 | -------------------------------------------------------------------------------- /js/images/graphic-gateway-placement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/js/images/graphic-gateway-placement.png -------------------------------------------------------------------------------- /js/images/graphic-gateway-setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/js/images/graphic-gateway-setup.png -------------------------------------------------------------------------------- /js/images/graphic-setup-elsys.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/js/images/graphic-setup-elsys.png -------------------------------------------------------------------------------- /js/images/myDevicesWhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/js/images/myDevicesWhite.png -------------------------------------------------------------------------------- /js/images/mydevices.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/js/images/mydevices.png -------------------------------------------------------------------------------- /js/images/tankBg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/js/images/tankBg.jpg -------------------------------------------------------------------------------- /js/lib/auth.interceptor.js: -------------------------------------------------------------------------------- 1 | import AuthService from './auth.service'; 2 | import NavigatorService from './navigation.service'; 3 | import _ from 'lodash'; 4 | 5 | Service = { 6 | request: request 7 | } 8 | 9 | function request(requestInfo, requestInit){ 10 | let params = getQueryParameters(requestInfo); 11 | if(!params.user_id){ 12 | let jwt = parseJwt(requestInit.headers.Authoriation); 13 | if(params.length > 0){ 14 | requestInfo += '?user_id=' + jwt.user_id; 15 | }else{ 16 | requestInfo += '&user_id=' + jwt.user_id; 17 | } 18 | } 19 | return fetch(requestInfo, requestInit) 20 | .then((response) => { 21 | if (response.status === 401) { 22 | // the request was reject for auth reason 23 | // trying to get a new token 24 | return AuthService.refreshToken() 25 | .then(() => { 26 | // we got a new token, retrying the original request: 27 | return fetch(requestInfo, requestInit); 28 | }) 29 | .catch(() => { 30 | // failed to get a new token 31 | // navigating back to login screen: 32 | return NavigatorService.navigate('Login'); 33 | }); 34 | } 35 | return response; 36 | }); 37 | } 38 | 39 | function getQueryParameters(url){ 40 | var regex = /[?&]([^=#]+)=([^&#]*)/g, 41 | params = {} 42 | match; 43 | while(match = regex.exec(url)) { 44 | params[match[1]] = match[2]; 45 | } 46 | return params; 47 | } 48 | 49 | function parseJwt (token) { 50 | var base64Url = token.split('.')[1]; 51 | var base64 = base64Url.replace('-', '+').replace('_', '/'); 52 | return JSON.parse(window.atob(base64)); 53 | }; 54 | 55 | export default Service; -------------------------------------------------------------------------------- /js/lib/auth.service.js: -------------------------------------------------------------------------------- 1 | import settings from '../config/settings'; 2 | import StorageService from './storage.service'; 3 | import PlatformService from './platform.service'; 4 | 5 | // Methods 6 | var Service = { 7 | getToken: getToken, 8 | refreshToken: refreshToken, 9 | forgotPassword: forgotPassword, 10 | getOauth: getOauth, 11 | createUser: createUser, 12 | getUser: getUser 13 | } 14 | 15 | /** 16 | * Get the authorization host 17 | * 18 | * @returns {String} 19 | */ 20 | function getHost() { 21 | return settings.authHost; 22 | } 23 | 24 | /** 25 | * Get the headers used for API calls 26 | * 27 | * @returns {*} 28 | */ 29 | function getHeaders() { 30 | return { 31 | 'Accept': 'application/json', 32 | 'Content-Type': 'application/json' 33 | } 34 | } 35 | 36 | function handleAuthResponse(data){ 37 | return Promise.all([ 38 | StorageService.set('access_token', data.access_token), 39 | StorageService.set('refresh_token', data.refresh_token) 40 | ]).then(() => { 41 | return data; 42 | }) 43 | } 44 | 45 | /** 46 | * Requests an oauth token using email/password 47 | * 48 | * @param {String} email 49 | * @param {String} password 50 | */ 51 | function getToken(email, password) { 52 | return fetch(getHost() + 'oauth/token', { 53 | method: 'POST', 54 | headers: getHeaders(), 55 | body: JSON.stringify({ 56 | email: email, 57 | password: password, 58 | client_id: settings.appKey, 59 | client_secret: settings.appSecret, 60 | grant_type: 'password' 61 | }) 62 | }) 63 | .then((response) => { 64 | return response.json().then(handleAuthResponse); 65 | }); 66 | } 67 | 68 | function refreshToken(){ 69 | return StorageService.get('refresh_token').then((refresh_token) => { 70 | if(!refresh_token) { 71 | return Promise.reject('no refresh token'); 72 | } 73 | return fetch(getHost() + 'oauth/token', { 74 | method: 'POST', 75 | headers: getHeaders(), 76 | body: JSON.stringify({ 77 | grant_type: 'refresh_token', 78 | refresh_token: refresh_token 79 | }) 80 | }) 81 | .then((response) => { 82 | if(response.status !== 200) throw new Error("refresh failed"); 83 | return response.json().then(handleAuthResponse); 84 | }); 85 | }); 86 | } 87 | 88 | /** 89 | * Gets oauth token using auth code, app id, app secret 90 | * 91 | * @param {String} authCode 92 | */ 93 | function getOauth(authCode) { 94 | return fetch(getHost() + 'oauth/token', { 95 | method: 'POST', 96 | headers: getHeaders(), 97 | body: JSON.stringify({ 98 | client_id: settings.appKey, 99 | client_secret: settings.appSecret, 100 | code: authCode, 101 | grant_type: "authorization_code", 102 | redirect_uri: settings.explicitUrl 103 | }) 104 | }) 105 | .then((response) => { 106 | return response.json().then(handleAuthResponse); 107 | }); 108 | } 109 | 110 | /** 111 | * Sends a forgot password request to authorization host 112 | * 113 | * @param {String} email 114 | */ 115 | function forgotPassword(email) { 116 | return fetch(getHost() + 'password/forgot', { 117 | method: 'POST', 118 | headers: getHeaders(), 119 | body: JSON.stringify({ 120 | email: email 121 | }) 122 | }) 123 | .then((response) => { 124 | return response.json(); 125 | }); 126 | } 127 | 128 | /** 129 | * Create a user 130 | * 131 | * @param {string} email 132 | * @param {string} password 133 | * @param {string} firstName 134 | * @param {string} lastName 135 | */ 136 | function createUser(email, password, firstName, lastName) { 137 | return fetch(getHost() + 'users', { 138 | method: 'POST', 139 | headers: getHeaders(), 140 | body: JSON.stringify({ 141 | email, 142 | first_name: firstName, 143 | last_name: lastName, 144 | password, 145 | application_id: settings.appKey 146 | }) 147 | }) 148 | .then((response) => { 149 | return response.json(); 150 | }); 151 | } 152 | 153 | /** 154 | * get the current user 155 | */ 156 | async function getUser() { 157 | let headers = getHeaders(); 158 | headers.Authorization = `Bearer ${await StorageService.get('access_token')}`; 159 | return fetch(getHost() + 'users/me', { 160 | method: 'get', 161 | headers: headers 162 | }) 163 | .then((response) => { 164 | return response.json(); 165 | }); 166 | } 167 | 168 | export default Service; 169 | -------------------------------------------------------------------------------- /js/lib/history.service.js: -------------------------------------------------------------------------------- 1 | import settings from '../config/settings'; 2 | import StorageService from './storage.service'; 3 | import StreamingService from './streaming.service'; 4 | import PlatformService from './platform.service'; 5 | import HttpService from './auth.interceptor'; 6 | 7 | export default class HistoryService{ 8 | 9 | /** 10 | * Get headers used for API calls 11 | * 12 | * @returns {*} 13 | */ 14 | static async getHeaders() { 15 | return { 16 | 'Authorization': `Bearer ${await StorageService.get('access_token')}` 17 | } 18 | } 19 | 20 | static async getState(deviceId){ 21 | var url = settings.historyHost + deviceId + '/state'; 22 | return HttpService.request( 23 | url, 24 | { 25 | method: 'GET', 26 | headers: await this.getHeaders() 27 | }) 28 | .then(function(response){ 29 | return Promise.all([ 30 | response.json(), 31 | PlatformService.getDataTypes() 32 | ]).then((promises)=>{ 33 | var data = promises[0]; 34 | var datatypes = promises[1]; 35 | data.map((value) => { 36 | var datatype = datatypes.find((type) => { 37 | return type.payload_type === value.type; 38 | }); 39 | 40 | var unit = datatype.units.find((unit) => { 41 | return unit.payload_unit === value.unit; 42 | }); 43 | 44 | fakeStreamingEvent = [ 45 | 'data-changed', 46 | { 47 | thingId: deviceId, 48 | channel: value.channel, 49 | value: { 50 | value: value.value, 51 | label: unit.unit_label 52 | } 53 | } 54 | ]; 55 | StreamingService.getInstance().notify({data: JSON.stringify(fakeStreamingEvent)}); 56 | }); 57 | return data; 58 | }); 59 | }); 60 | } 61 | } -------------------------------------------------------------------------------- /js/lib/index.js: -------------------------------------------------------------------------------- 1 | import AuthService from './auth.service'; 2 | import PlatformService from './platform.service'; 3 | import StreamingService from './streaming.service'; 4 | import HistoryService from './history.service'; 5 | import StorageService from './storage.service'; 6 | import RulesService from './rule.service'; 7 | 8 | 9 | export { AuthService }; 10 | export { PlatformService }; 11 | export { StreamingService }; 12 | export { HistoryService }; 13 | export { StorageService }; 14 | export { RulesService }; -------------------------------------------------------------------------------- /js/lib/navigation.service.js: -------------------------------------------------------------------------------- 1 | import { NavigationActions } from 'react-navigation'; 2 | 3 | let _container; // eslint-disable-line 4 | 5 | function navigate(routeName, params) { 6 | _container.dispatch( 7 | NavigationActions.navigate({ 8 | type: 'Navigation/NAVIGATE', 9 | routeName, 10 | params, 11 | }), 12 | ); 13 | } 14 | 15 | function setContainer(container){ 16 | _container = container; 17 | } 18 | 19 | export default { 20 | navigate, 21 | setContainer 22 | }; -------------------------------------------------------------------------------- /js/lib/platform.service.js: -------------------------------------------------------------------------------- 1 | import settings from '../config/settings'; 2 | import StorageService from './storage.service'; 3 | import HttpService from './auth.interceptor'; 4 | 5 | /** 6 | * Public methods 7 | */ 8 | var Service = { 9 | getThings: getThings, 10 | pairGateway: pairGateway, 11 | addThing: addThing, 12 | createClient: createClient, 13 | deleteThing: deleteThing, 14 | getDataTypes: dataTypes, 15 | getThingsTypes: getThingsTypes, 16 | getTypeChannels: getTypeChannels 17 | } 18 | 19 | /** 20 | * Get Things API host 21 | * 22 | * @returns {String} 23 | */ 24 | function getHost() { 25 | return settings.apiHost; 26 | } 27 | 28 | /** 29 | * Get headers used for API calls 30 | * 31 | * @returns {*} 32 | */ 33 | async function getHeaders() { 34 | 35 | return { 36 | 'Accept': 'application/json', 37 | 'Content-Type': 'application/json', 38 | 'Authorization': `Bearer ${await StorageService.get('access_token')}` 39 | } 40 | } 41 | 42 | /** 43 | * Get things attached to current account 44 | * 45 | * @returns {*} 46 | */ 47 | async function getThings() { 48 | return HttpService.request(getHost() + 'things', { 49 | method: 'GET', 50 | headers: await getHeaders() 51 | }) 52 | .then((response) => { 53 | return response.json(); 54 | }); 55 | } 56 | 57 | /** 58 | * Get things types 59 | * 60 | * @returns {*} 61 | */ 62 | async function getThingsTypes() { 63 | return HttpService.request(getHost() + 'things/types', { 64 | method: 'GET', 65 | headers: await getHeaders() 66 | }) 67 | .then((response) => { 68 | return response.json(); 69 | }); 70 | } 71 | 72 | /** 73 | * Get things types 74 | * 75 | * @returns {*} 76 | */ 77 | async function getTypeChannels(typeId) { 78 | return HttpService.request(getHost() + `things/types/${typeId}/channels`, { 79 | method: 'GET', 80 | headers: await getHeaders() 81 | }) 82 | .then((response) => { 83 | return response.json(); 84 | }); 85 | } 86 | 87 | 88 | /** 89 | * Pair a gateway 90 | * 91 | * @param {String} gatewayName 92 | * @param {String} gatewayId 93 | * @returns {*} 94 | */ 95 | async function pairGateway(gatewayName, gatewayId) { 96 | return HttpService.request(getHost() + 'things/pair', { 97 | method: 'POST', 98 | headers: await getHeaders(), 99 | body: JSON.stringify({ 100 | hardware_id: gatewayId, 101 | name: gatewayName 102 | }) 103 | }) 104 | .then((response) => { 105 | return response.json(); 106 | }); 107 | } 108 | 109 | /** 110 | * Add a thing 111 | * 112 | * @param {String} thing 113 | * @returns {*} 114 | */ 115 | async function addThing(thing) { 116 | return HttpService.request(getHost() + 'things', { 117 | method: 'POST', 118 | headers: await getHeaders(), 119 | body: JSON.stringify(thing) 120 | }) 121 | .then((response) => { 122 | return response.json(); 123 | }); 124 | } 125 | 126 | /** 127 | * Create a MQTT client credentials 128 | * 129 | * @returns {*} 130 | */ 131 | async function createClient(userId) { 132 | return HttpService.request(getHost() + 'clients', { 133 | method: 'POST', 134 | headers: await getHeaders(), 135 | body: JSON.stringify({ 136 | user_id: userId 137 | }) 138 | }) 139 | .then((response) => { 140 | return response.json(); 141 | }); 142 | } 143 | 144 | /** 145 | * Delete a thing 146 | * 147 | * @param {String} thingId 148 | */ 149 | async function deleteThing(thingId) { 150 | return HttpService.request(getHost() + `things/${thingId}`, { 151 | method: 'DELETE', 152 | headers: await getHeaders() 153 | }) 154 | .then((response) => { 155 | return response.json(); 156 | }); 157 | } 158 | 159 | async function dataTypes(){ 160 | return HttpService.request(getHost() + `ui/datatypes`, { 161 | method: 'GET', 162 | headers: await getHeaders() 163 | }) 164 | .then((response) => { 165 | return response.json(); 166 | }); 167 | } 168 | 169 | export default Service; 170 | -------------------------------------------------------------------------------- /js/lib/rule.service.js: -------------------------------------------------------------------------------- 1 | import settings from '../config/settings'; 2 | import HttpService from './auth.interceptor'; 3 | 4 | // Methods 5 | var Service = { 6 | getDeviceTypeRules: getDeviceTypeRules, 7 | setRule: setRule 8 | } 9 | 10 | /** 11 | * Get the authorization host 12 | * 13 | * @returns {String} 14 | */ 15 | function getHost() { 16 | return settings.rulesHost; 17 | } 18 | 19 | 20 | /** 21 | * Get headers used for API calls 22 | * 23 | * @returns {*} 24 | */ 25 | async function getHeaders() { 26 | return { 27 | 'Authorization': `Bearer ${await StorageService.get('access_token')}` 28 | } 29 | } 30 | 31 | 32 | function getDeviceTypeRules(deviceTypeId){ 33 | var appId = settings.appKey; 34 | var url = getHost + '/v1.0/applicationRule/' + deviceTypeId + '/' + appId; 35 | 36 | return getHeaders().then((headers) => { 37 | return HttpService.request(url, {method: 'GET', headers: headers}); 38 | }).then((response) => { 39 | return response.json(); 40 | }); 41 | } 42 | 43 | function setRule(rule){ 44 | var url = getHost + '/v1.0/rules'; 45 | 46 | return getHeaders().then((headers) => { 47 | return HttpService.request( 48 | url, 49 | { 50 | method: 'POST', 51 | headers: headers, 52 | body: JSON.stringify(rule) 53 | } 54 | ); 55 | }).then((response) => { 56 | return response.json(); 57 | }); 58 | } 59 | -------------------------------------------------------------------------------- /js/lib/storage.service.js: -------------------------------------------------------------------------------- 1 | import { AsyncStorage } from 'react-native'; 2 | 3 | // Methods 4 | var Service = { 5 | getAsync: getData, 6 | setAsync: setData, 7 | removeAsync: removeData, 8 | get: getData, 9 | set: setData, 10 | remove: removeData 11 | } 12 | 13 | async function getData(key){ 14 | return AsyncStorage.getItem(key); 15 | } 16 | 17 | async function setData(key, value){ 18 | return AsyncStorage.setItem(key, value); 19 | } 20 | 21 | async function removeData(key){ 22 | return AsyncStorage.removeItem(key); 23 | } 24 | 25 | async function getDataAsync(key){ 26 | return await AsyncStorage.getItem(key); 27 | } 28 | 29 | async function setDataAsync(key, value){ 30 | return await AsyncStorage.setItem(key, value); 31 | } 32 | 33 | async function removeDataAsync(key){ 34 | return await AsyncStorage.removeItem(key); 35 | } 36 | 37 | export default Service; -------------------------------------------------------------------------------- /js/lib/streaming.service.js: -------------------------------------------------------------------------------- 1 | import settings from '../config/settings'; 2 | import StorageService from '../lib/storage.service'; 3 | import UtilsService from './utils.service'; 4 | 5 | export default class StreamingService{ 6 | static _instance = null; 7 | _subscribers = {}; 8 | 9 | 10 | constructor(){ 11 | this.init(); 12 | } 13 | 14 | async init(){ 15 | var url = settings.streamingHost + `?token=${await StorageService.get('access_token')}&transport=websocket`; 16 | url=url.replace('https', 'wss'); 17 | var ws = new WebSocket(url); 18 | 19 | ws.onmessage = this.notify.bind(this); 20 | 21 | ws.onerror = (e) => { 22 | // an error occurred 23 | console.log(e.message); 24 | }; 25 | 26 | ws.onclose = this.init.bind(this); 27 | } 28 | 29 | notify(event){ 30 | if(event.data){ 31 | var index = event.data.indexOf('['); 32 | var payload = event.data.substring(index, event.data.length); 33 | try{ 34 | payload = JSON.parse(payload); 35 | if(payload[0] === 'data-changed'){ 36 | var subscribers = this._subscribers[payload[0] + payload[1].thingId + payload[1].channel]; 37 | if(subscribers){ 38 | subscribers.map(function(subscriber){ 39 | subscriber.cb(payload[1].value); 40 | }); 41 | } 42 | } 43 | }catch(e){} 44 | } 45 | } 46 | 47 | 48 | subscribe(topic, deviceId, channel, cb){ 49 | var subscriberId = UtilsService.guid(); 50 | if(!this._subscribers[topic + deviceId + channel]){ 51 | this._subscribers[topic + deviceId + channel] = []; 52 | } 53 | this._subscribers[topic + deviceId + channel].push({id: subscriberId, cb: cb}); 54 | return subscriberId; 55 | } 56 | 57 | unsubscribe(topic, deviceId, channel, subscriberId){ 58 | var subscribers = this._subscribers[topic + deviceId + channel]; 59 | var toRemove = subscribers.find((subscriber) => { return subscriber.id === subscriberId; }) 60 | if(toRemove){ 61 | subscribers.splice(subscribers.indexOf(toRemove), 1); 62 | } 63 | } 64 | 65 | 66 | static getInstance(){ 67 | if(this._instance == null){ 68 | this._instance = new StreamingService(); 69 | } 70 | return this._instance; 71 | } 72 | } -------------------------------------------------------------------------------- /js/lib/utils.service.js: -------------------------------------------------------------------------------- 1 | Service = { 2 | guid: guid 3 | } 4 | 5 | function guid() { 6 | function s4() { 7 | return Math.floor((1 + Math.random()) * 0x10000) 8 | .toString(16) 9 | .substring(1); 10 | } 11 | return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4(); 12 | } 13 | 14 | export default Service; -------------------------------------------------------------------------------- /js/routes/router.js: -------------------------------------------------------------------------------- 1 | import { StackNavigator } from 'react-navigation'; 2 | import SCREENS from './../screens/index'; 3 | 4 | export default ROUTES = StackNavigator({ 5 | Splash: {screen: SCREENS.Splash}, 6 | CreateName: { screen: SCREENS.CreateName }, 7 | CreateEmail: { screen: SCREENS.CreateEmail }, 8 | Login: { screen: SCREENS.LoginScreen }, 9 | ForgotPassword: { screen: SCREENS.ForgotPassword }, 10 | GatewaySetup: { screen: SCREENS.GatewaySetup }, 11 | SensorSetup: { screen: SCREENS.SensorSetup }, 12 | Status: { screen: SCREENS.Status }, 13 | Alerts: { screen: SCREENS.Alerts }, 14 | SensorMap: { screen: SCREENS.SensorMap } 15 | }); 16 | -------------------------------------------------------------------------------- /js/screens/add-device.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myDevicesIoT/Cayenne-API-Sample-App/7a857cd8f06129259ae467411a074ecefcced236/js/screens/add-device.js -------------------------------------------------------------------------------- /js/screens/alerts.js: -------------------------------------------------------------------------------- 1 | import React, { 2 | Component 3 | } from 'react'; 4 | import { 5 | View, 6 | Text, 7 | ScrollView 8 | } from 'react-native'; 9 | import { 10 | StackNavigator 11 | } from 'react-navigation'; 12 | import { 13 | Footer, 14 | CommonStyles, 15 | Header 16 | } from './../components/index'; 17 | 18 | class Alerts extends Component { 19 | static navigationOptions = {header: null}; 20 | render() { 21 | const {navigate} = this.props.navigation; 22 | return ( 23 | 24 |
navigate('SensorSetup', screenProps = {gateway: 'alerts'})}/> 25 | 26 | 27 | 28 | 29 | 30 | 31 |