├── README.md
├── examples
├── wifi_config
│ ├── server
│ ├── readme
│ ├── exec.hpp
│ ├── Makefile
│ ├── main.cpp
│ ├── gpiopin.hpp
│ ├── index.html
│ ├── wireless.hpp
│ └── server.hpp
├── Glass_PhillipsHue
│ ├── glass_app
│ │ ├── lib
│ │ │ ├── gson-2.2.jar
│ │ │ └── android-support-v4.jar
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── light_off.png
│ │ │ │ ├── light_on.png
│ │ │ │ ├── light_scene2.png
│ │ │ │ ├── light_scene3.png
│ │ │ │ └── light_scene.1.png
│ │ │ └── layout
│ │ │ │ └── layout_stopwatch.xml
│ │ ├── src
│ │ │ ├── com
│ │ │ │ └── dataart
│ │ │ │ │ └── android
│ │ │ │ │ └── devicehive
│ │ │ │ │ ├── DeviceHive.java
│ │ │ │ │ ├── client
│ │ │ │ │ ├── commands
│ │ │ │ │ │ ├── DeviceClientCommand.java
│ │ │ │ │ │ ├── PollNotificationsCommand.java
│ │ │ │ │ │ ├── GetDeviceNotificationsCommand.java
│ │ │ │ │ │ ├── GetNetworksCommand.java
│ │ │ │ │ │ ├── GetDevicesCommand.java
│ │ │ │ │ │ ├── GetDeviceCommand.java
│ │ │ │ │ │ ├── NotificationsRetrivalCommand.java
│ │ │ │ │ │ ├── GetCommandCommand.java
│ │ │ │ │ │ ├── PollDeviceNotificationsCommand.java
│ │ │ │ │ │ ├── SendDeviceCommandCommand.java
│ │ │ │ │ │ ├── GetNetworkDevicesCommand.java
│ │ │ │ │ │ ├── GetDeviceEquipmentStateCommand.java
│ │ │ │ │ │ ├── GetDeviceClassEquipmentCommand.java
│ │ │ │ │ │ └── PollMultipleDeviceNotificationsCommand.java
│ │ │ │ │ ├── SingleDeviceClient.java
│ │ │ │ │ ├── MultipleDeviceClient.java
│ │ │ │ │ ├── DeviceClient.java
│ │ │ │ │ └── ClientServiceConnection.java
│ │ │ │ │ ├── ObjectWrapper.java
│ │ │ │ │ ├── device
│ │ │ │ │ ├── EquipmentNotification.java
│ │ │ │ │ ├── DeviceStatusNotification.java
│ │ │ │ │ ├── CommandRunner.java
│ │ │ │ │ ├── commands
│ │ │ │ │ │ ├── DeviceCommand.java
│ │ │ │ │ │ ├── GetDeviceCommandsCommand.java
│ │ │ │ │ │ ├── DeviceCommandsRetrivalCommand.java
│ │ │ │ │ │ ├── RegisterDeviceCommand.java
│ │ │ │ │ │ ├── GetDeviceCommand.java
│ │ │ │ │ │ ├── PollDeviceCommandsCommand.java
│ │ │ │ │ │ ├── SendNotificationCommand.java
│ │ │ │ │ │ └── UpdateCommandStatusCommand.java
│ │ │ │ │ ├── CommandResult.java
│ │ │ │ │ └── Equipment.java
│ │ │ │ │ ├── DataContainer.java
│ │ │ │ │ ├── ApiInfo.java
│ │ │ │ │ ├── commands
│ │ │ │ │ └── GetApiInfoCommand.java
│ │ │ │ │ ├── EquipmentState.java
│ │ │ │ │ ├── EquipmentData.java
│ │ │ │ │ ├── Network.java
│ │ │ │ │ ├── Notification.java
│ │ │ │ │ ├── network
│ │ │ │ │ ├── ServiceConnection.java
│ │ │ │ │ ├── NetworkCommandConfig.java
│ │ │ │ │ ├── DeviceHiveApiService.java
│ │ │ │ │ ├── JsonNetworkCommand.java
│ │ │ │ │ └── DeviceHiveResultReceiver.java
│ │ │ │ │ ├── Command.java
│ │ │ │ │ ├── DeviceClass.java
│ │ │ │ │ └── DeviceData.java
│ │ │ └── org
│ │ │ │ └── devicehive
│ │ │ │ └── glass
│ │ │ │ ├── NeuralyzerActivity.java
│ │ │ │ └── PhillipsHueDevice.java
│ │ └── AndroidManifest.xml
│ └── python_gateway
│ │ └── philips_hue_example.py
└── RainbowCube
│ ├── html
│ ├── cube.html
│ └── js
│ │ └── app.js
│ └── firmware
│ └── firmware.ino
├── LICENSE
└── .gitmodules
/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devicehive/framework/HEAD/README.md
--------------------------------------------------------------------------------
/examples/wifi_config/server:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devicehive/framework/HEAD/examples/wifi_config/server
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/lib/gson-2.2.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devicehive/framework/HEAD/examples/Glass_PhillipsHue/glass_app/lib/gson-2.2.jar
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/lib/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devicehive/framework/HEAD/examples/Glass_PhillipsHue/glass_app/lib/android-support-v4.jar
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ff000000
4 |
5 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/res/drawable-hdpi/light_off.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devicehive/framework/HEAD/examples/Glass_PhillipsHue/glass_app/res/drawable-hdpi/light_off.png
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/res/drawable-hdpi/light_on.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devicehive/framework/HEAD/examples/Glass_PhillipsHue/glass_app/res/drawable-hdpi/light_on.png
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/res/drawable-hdpi/light_scene2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devicehive/framework/HEAD/examples/Glass_PhillipsHue/glass_app/res/drawable-hdpi/light_scene2.png
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/res/drawable-hdpi/light_scene3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devicehive/framework/HEAD/examples/Glass_PhillipsHue/glass_app/res/drawable-hdpi/light_scene3.png
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/res/drawable-hdpi/light_scene.1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/devicehive/framework/HEAD/examples/Glass_PhillipsHue/glass_app/res/drawable-hdpi/light_scene.1.png
--------------------------------------------------------------------------------
/examples/wifi_config/readme:
--------------------------------------------------------------------------------
1 | server binary is pre-built for RPi
2 |
3 | Build dependencies:
4 |
5 | 1. wireless tools (http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/Tools.html)
6 | 2. mongoose server (https://code.google.com/p/mongoose/)
7 | 3. mongocpp (http://code.google.com/r/vpiotr-mongoose-cpp/)
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | GlassMoodLamp
4 | GlassMoodLamp
5 |
6 | Tap to Light OffTap to Light On
7 |
8 |
9 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/src/com/dataart/android/devicehive/DeviceHive.java:
--------------------------------------------------------------------------------
1 | package com.dataart.android.devicehive;
2 |
3 | /**
4 | * Some declarations which are intended for internal use.
5 | */
6 | public class DeviceHive {
7 | /**
8 | * Logging TAG.
9 | */
10 | public final static String TAG = "DeviceHive";
11 | }
12 |
--------------------------------------------------------------------------------
/examples/wifi_config/exec.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 |
7 | std::string exec(const std::string& cmd)
8 | {
9 | std::string result;
10 |
11 | FILE* pipe = popen(cmd.c_str(), "r");
12 | if (!pipe) return "ERROR";
13 |
14 | char buffer[128];
15 | while(!feof(pipe)) {
16 | if(fgets(buffer, 128, pipe) != NULL)
17 | result += buffer;
18 | }
19 | pclose(pipe);
20 |
21 | return result;
22 | }
23 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/src/com/dataart/android/devicehive/client/commands/DeviceClientCommand.java:
--------------------------------------------------------------------------------
1 | package com.dataart.android.devicehive.client.commands;
2 |
3 | import android.os.Parcel;
4 |
5 | import com.dataart.android.devicehive.network.JsonNetworkCommand;
6 |
7 | /**
8 | * Base command for Device Hive device client commands.
9 | */
10 | public abstract class DeviceClientCommand extends JsonNetworkCommand {
11 |
12 | @Override
13 | public int describeContents() {
14 | return 0;
15 | }
16 |
17 | @Override
18 | public void writeToParcel(Parcel dest, int flags) {
19 |
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/src/com/dataart/android/devicehive/ObjectWrapper.java:
--------------------------------------------------------------------------------
1 | package com.dataart.android.devicehive;
2 |
3 | import java.io.Serializable;
4 |
5 | public class ObjectWrapper implements Serializable {
6 |
7 | private static final long serialVersionUID = -7373759268902337088L;
8 |
9 | private final T object;
10 |
11 | public ObjectWrapper(T object) {
12 | this.object = object;
13 | }
14 |
15 | public T getObject() {
16 | return object;
17 | }
18 |
19 | @Override
20 | public String toString() {
21 | if (object == null) {
22 | return "" + object;
23 | } else {
24 | return object.toString();
25 | }
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
9 |
10 |
14 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/res/layout/layout_stopwatch.xml:
--------------------------------------------------------------------------------
1 |
8 |
15 |
16 |
17 |
22 |
23 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | DeviceHive is developed by DataArt Apps and distributed under MIT license.
2 |
3 | Copyright (C) 2015 DataArt Apps
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 | of the Software, and to permit persons to whom the Software is furnished to do
10 | 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 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/src/com/dataart/android/devicehive/device/EquipmentNotification.java:
--------------------------------------------------------------------------------
1 | package com.dataart.android.devicehive.device;
2 |
3 | import java.util.HashMap;
4 |
5 | import com.dataart.android.devicehive.Notification;
6 |
7 | /**
8 | * Represents a {@link Notification} which is usually sent by an
9 | * {@link Equipment} to update its state.
10 | */
11 | public class EquipmentNotification extends Notification {
12 |
13 | /**
14 | * Construct a notification with given equipment code and additional
15 | * equipment parameters dictionary.
16 | *
17 | * @param equipmentCode
18 | * Equipment code.
19 | * @param parameters
20 | * Equipment parameters dictionary.
21 | */
22 | public EquipmentNotification(String equipmentCode,
23 | HashMap parameters) {
24 | super("equipment", equipmentParameters(equipmentCode, parameters));
25 | }
26 |
27 | private static HashMap equipmentParameters(
28 | String equipmentCode, HashMap parameters) {
29 | final HashMap equipmentParameters = new HashMap(
30 | parameters);
31 | parameters.put("equipment", equipmentCode);
32 | return equipmentParameters;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "ios"]
2 | path = ios
3 | url = https://github.com/devicehive/devicehive-ios.git
4 | [submodule "cpp"]
5 | path = cpp
6 | url = https://github.com/devicehive/devicehive-cpp.git
7 | [submodule "android"]
8 | path = android
9 | url = https://github.com/devicehive/devicehive-android.git
10 | [submodule "admin-console"]
11 | path = admin-console
12 | url = https://github.com/devicehive/devicehive-admin-console.git
13 | [submodule "javascript"]
14 | path = javascript
15 | url = https://github.com/devicehive/devicehive-javascript.git
16 | [submodule "uc"]
17 | path = uc
18 | url = https://github.com/devicehive/devicehive-uc.git
19 | [submodule "python"]
20 | path = python
21 | url = https://github.com/devicehive/devicehive-python.git
22 | [submodule "arduino"]
23 | path = arduino
24 | url = https://github.com/devicehive/devicehive-arduino.git
25 | [submodule "j2me"]
26 | path = j2me
27 | url = https://github.com/devicehive/devicehive-j2me.git
28 | [submodule "net"]
29 | path = net
30 | url = https://github.com/devicehive/devicehive-.net.git
31 | [submodule "net-mf"]
32 | path = net-mf
33 | url = https://github.com/devicehive/devicehive-.net-mf.git
34 | [submodule "java"]
35 | path = java
36 | url = https://github.com/devicehive/devicehive-java.git
37 |
--------------------------------------------------------------------------------
/examples/wifi_config/Makefile:
--------------------------------------------------------------------------------
1 | # use CROSS_COMPILE variable to set toolchain (empty by default):
2 | # >make CROSS_COMPILE=arm-linux-gnueabi-
3 |
4 | # build variant: 'debug' or 'release' (by default)
5 | # to change use VARIANT variable:
6 | # >make VARIANT=debug
7 | # >make VARIANT=release
8 | variant:=release
9 | ifdef VARIANT
10 | ifeq '${VARIANT}' 'release'
11 | variant:=release
12 | else ifeq '${VARIANT}' 'debug'
13 | variant:=debug
14 | else
15 | $(error '${VARIANT}' is unknown variant, expected: release or debug)
16 | endif
17 | endif
18 |
19 | # platform helper
20 | ifdef PLATFORM
21 | platform=${PLATFORM}
22 | else
23 | platform:=$(shell uname -m)
24 | endif
25 |
26 |
27 | ifeq '${variant}' 'debug'
28 | defines+=-D_DEBUG
29 | defines+=-g
30 | else # default
31 | defines+=-DNDEBUG
32 | defines+=-Os
33 | endif
34 |
35 |
36 | CXXFLAGS+=-Wall ${include_dirs} ${defines} -std=gnu++0x
37 | #CXXFLAGS+=-fdata-sections -ffunction-sections
38 | #LDFLAGS+=-Wl,--gc-sections -pthread -L${ex_libs}
39 |
40 |
41 | server: main.cpp exec.hpp gpiopin.hpp server.hpp wireless.hpp
42 | g++ -o server main.cpp ${CXXFLAGS} ${LDFLAGS} \
43 | -liw -lmongoose -lmongocpp
44 |
45 |
46 | #########################################################
47 | # clean all the object files and applications
48 | clean:
49 | @rm -rf *.o
50 | @rm -f server
51 |
52 |
53 | .PHONY: clean
54 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/src/com/dataart/android/devicehive/DataContainer.java:
--------------------------------------------------------------------------------
1 | package com.dataart.android.devicehive;
2 |
3 | import java.io.Serializable;
4 |
5 | import android.os.Parcel;
6 | import android.os.Parcelable;
7 |
8 | /* package */abstract class DataContainer implements Parcelable {
9 |
10 | protected ObjectWrapper data;
11 |
12 | protected DataContainer() {
13 | this(null);
14 | }
15 |
16 | protected DataContainer(Serializable data) {
17 | setData(data);
18 | }
19 |
20 | /**
21 | * Set equipment data, an object with an arbitrary structure that can be
22 | * serialized to JSON. Equipment data can only be set/changed before device
23 | * registration.
24 | *
25 | * @param data
26 | * An object that can be serialized to JSON.
27 | */
28 | public void setData(Serializable data) {
29 | this.data = new ObjectWrapper(data);
30 | }
31 |
32 | /**
33 | * Get device data.
34 | *
35 | * @return An object with arbitrary structure. Typically, an object is
36 | * constructed using StringMaps, ArrayLists and primitives.
37 | */
38 | public Object getData() {
39 | return data != null ? data.getObject() : data;
40 | }
41 |
42 | @Override
43 | public int describeContents() {
44 | return 0;
45 | }
46 |
47 | @Override
48 | public void writeToParcel(Parcel dest, int flags) {
49 | dest.writeSerializable(data != null ? data.getObject() : data);
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/src/com/dataart/android/devicehive/device/DeviceStatusNotification.java:
--------------------------------------------------------------------------------
1 | package com.dataart.android.devicehive.device;
2 |
3 | import java.util.HashMap;
4 |
5 | import com.dataart.android.devicehive.DeviceData;
6 | import com.dataart.android.devicehive.Notification;
7 |
8 | /**
9 | * Represents a device status notification which is sent by {@link Device} when
10 | * its status changes.
11 | */
12 | public class DeviceStatusNotification extends Notification {
13 |
14 | /**
15 | * Predefined "Online" device status notification.
16 | */
17 | public static final DeviceStatusNotification STATUS_ONLINE = new DeviceStatusNotification(
18 | DeviceData.DEVICE_STATUS_ONLINE);
19 |
20 | /**
21 | * Predefined "OK" device status notification.
22 | */
23 | public static final DeviceStatusNotification STATUS_OK = new DeviceStatusNotification(
24 | DeviceData.DEVICE_STATUS_OK);
25 |
26 | /**
27 | * Construct device status notification with given device status.
28 | *
29 | * @param deviceStatus
30 | * Device status value.
31 | */
32 | public DeviceStatusNotification(String deviceStatus) {
33 | super("DeviceStatus", parametersWithDeviceStatus(deviceStatus));
34 | }
35 |
36 | private static HashMap parametersWithDeviceStatus(
37 | String deviceStatus) {
38 | HashMap parameters = new HashMap();
39 | parameters.put("status", deviceStatus);
40 | return parameters;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/src/com/dataart/android/devicehive/device/CommandRunner.java:
--------------------------------------------------------------------------------
1 | package com.dataart.android.devicehive.device;
2 |
3 | import com.dataart.android.devicehive.Command;
4 |
5 | /**
6 | * Common interface for objects able to execute commands. Usually these are
7 | * {@link Device} and {@link Equipment}.
8 | */
9 | public interface CommandRunner {
10 |
11 | /**
12 | * Called right before command is executed either by the device itself or
13 | * one of its equipment. This method is called for the device before each
14 | * command execution (either by the device itself or one of its equipment).
15 | *
16 | * @param command
17 | * {@link Command} to be executed.
18 | */
19 | void onBeforeRunCommand(Command command);
20 |
21 | /**
22 | * Check whether receiver of the command should execute command on some
23 | * other thread, not on the main (UI) thread.
24 | *
25 | * @param command
26 | * Command to be executed.
27 | * @return true if {@link #runCommand(Command)} should be called
28 | * asynchronously, otherwise returns false.
29 | */
30 | boolean shouldRunCommandAsynchronously(final Command command);
31 |
32 | /**
33 | * Execute given command. Cab be called either on the main thread or some
34 | * other thread. It depends on the value that is returned by
35 | * {@link #shouldRunCommandAsynchronously(Command)} method.
36 | *
37 | * @param command
38 | * Command to be executed.
39 | * @return {@link CommandResult} object describing command execution result
40 | * and status.
41 | */
42 | CommandResult runCommand(final Command command);
43 | }
44 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/src/com/dataart/android/devicehive/client/commands/PollNotificationsCommand.java:
--------------------------------------------------------------------------------
1 | package com.dataart.android.devicehive.client.commands;
2 |
3 | import android.os.Parcel;
4 |
5 | import com.google.gson.Gson;
6 |
7 | /**
8 | * Abstract base class for commands which poll notifications for given device.
9 | *
10 | */
11 | public abstract class PollNotificationsCommand extends
12 | NotificationsRetrivalCommand {
13 |
14 | protected final Integer waitTimeout;
15 |
16 | /**
17 | * Construct a new command with last received notification timestamp.
18 | *
19 | * @param lastNotificationPollTimestamp
20 | * Last received notification timestamp.
21 | */
22 | public PollNotificationsCommand(String lastNotificationPollTimestamp) {
23 | this(lastNotificationPollTimestamp, null);
24 | }
25 |
26 | /**
27 | * Construct a new command with last received notification timestamp and
28 | * wait timeout.
29 | *
30 | * @param lastNotificationPollTimestamp
31 | * Last received notification timestamp.
32 | * @param waitTimeout
33 | * Waiting timeout in seconds.
34 | */
35 | public PollNotificationsCommand(String lastNotificationPollTimestamp,
36 | Integer waitTimeout) {
37 | super(lastNotificationPollTimestamp);
38 | this.waitTimeout = waitTimeout;
39 | }
40 |
41 | @Override
42 | protected RequestType getRequestType() {
43 | return RequestType.GET;
44 | }
45 |
46 | @Override
47 | public void writeToParcel(Parcel dest, int flags) {
48 | super.writeToParcel(dest, flags);
49 | dest.writeValue(waitTimeout);
50 | }
51 |
52 | @Override
53 | protected String toJson(Gson gson) {
54 | return null;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/src/com/dataart/android/devicehive/device/commands/DeviceCommand.java:
--------------------------------------------------------------------------------
1 | package com.dataart.android.devicehive.device.commands;
2 |
3 | import java.util.Map;
4 |
5 | import android.os.Parcel;
6 |
7 | import com.dataart.android.devicehive.network.JsonNetworkCommand;
8 |
9 | /**
10 | * Base command for Device Hive device-related commands.
11 | */
12 | public abstract class DeviceCommand extends JsonNetworkCommand {
13 |
14 | protected final String deviceId;
15 | protected final String deviceKey;
16 |
17 | /**
18 | * Construct new command with given device data.
19 | *
20 | * @param deviceId
21 | * Device identifier.
22 | * @param deviceKey
23 | * Device key.
24 | */
25 | public DeviceCommand(String deviceId, String deviceKey) {
26 | this.deviceId = deviceId;
27 | this.deviceKey = deviceKey;
28 | }
29 |
30 | /**
31 | * Construct new command with given device data.
32 | *
33 | * @param deviceId
34 | * Device identifier.
35 | */
36 | public DeviceCommand(String deviceId) {
37 | this(deviceId, null);
38 | }
39 |
40 | protected boolean deviceAuthenticationRequired() {
41 | return true;
42 | }
43 |
44 | @Override
45 | protected Map getHeaders() {
46 | final Map headers = super.getHeaders();
47 | if (deviceAuthenticationRequired()) {
48 | addDeviceAuthentication(headers);
49 | }
50 | return headers;
51 | }
52 |
53 | protected String getEncodedDeviceId() {
54 | return encodedString(deviceId);
55 | }
56 |
57 | private void addDeviceAuthentication(Map headers) {
58 | headers.put("Auth-DeviceID", deviceId);
59 | headers.put("Auth-DeviceKey", deviceKey);
60 | }
61 |
62 | @Override
63 | public int describeContents() {
64 | return 0;
65 | }
66 |
67 | @Override
68 | public void writeToParcel(Parcel dest, int flags) {
69 | dest.writeString(deviceId);
70 | dest.writeString(deviceKey);
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/src/com/dataart/android/devicehive/device/commands/GetDeviceCommandsCommand.java:
--------------------------------------------------------------------------------
1 | package com.dataart.android.devicehive.device.commands;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | import com.dataart.android.devicehive.DeviceData;
7 |
8 | /**
9 | * Get commands for given device starting from given date timestamp. Server
10 | * returns response immediately regardless of whether there are any commands for
11 | * given device.
12 | */
13 | public class GetDeviceCommandsCommand extends DeviceCommandsRetrivalCommand {
14 |
15 | /**
16 | * Construct a new command with given {@link DeviceData} and last received
17 | * command timestamp.
18 | *
19 | * @param deviceId
20 | * Device unique identifier.
21 | * @param deviceKey
22 | * Device key.
23 | * @param lastCommandPollTimestamp
24 | * Timestamp of the last received command. If null value is
25 | * passed then server will return all command it's received so
26 | * far.
27 | */
28 | public GetDeviceCommandsCommand(String deviceId, String deviceKey,
29 | String lastCommandPollTimestamp) {
30 | super(deviceId, deviceKey, lastCommandPollTimestamp);
31 | }
32 |
33 | @Override
34 | protected String getRequestPath() {
35 | String requestPath = String.format("device/%s/command",
36 | getEncodedDeviceId());
37 | if (lastCommandPollTimestamp != null) {
38 | requestPath += "?start=" + encodedString(lastCommandPollTimestamp);
39 | }
40 | return requestPath;
41 | }
42 |
43 | public static Parcelable.Creator CREATOR = new Parcelable.Creator() {
44 |
45 | @Override
46 | public GetDeviceCommandsCommand[] newArray(int size) {
47 | return new GetDeviceCommandsCommand[size];
48 | }
49 |
50 | @Override
51 | public GetDeviceCommandsCommand createFromParcel(Parcel source) {
52 | return new GetDeviceCommandsCommand(source.readString(),
53 | source.readString(), source.readString());
54 | }
55 | };
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/src/com/dataart/android/devicehive/device/CommandResult.java:
--------------------------------------------------------------------------------
1 | package com.dataart.android.devicehive.device;
2 |
3 | import java.io.Serializable;
4 |
5 | import com.dataart.android.devicehive.ObjectWrapper;
6 |
7 | import android.os.Parcel;
8 | import android.os.Parcelable;
9 |
10 | /**
11 | * Command execution result which is reported to the server.
12 | */
13 | public class CommandResult implements Parcelable {
14 |
15 | /**
16 | * Command status "Completed" value.
17 | */
18 | public static final String STATUS_COMLETED = "Completed";
19 |
20 | /**
21 | * Command status "Failed" value.
22 | */
23 | public static final String STATUS_FAILED = "Failed";
24 |
25 | private final String status;
26 | private final ObjectWrapper result;
27 |
28 | /**
29 | * Constructs command result with given status and result.
30 | *
31 | * @param status
32 | * Command status.
33 | * @param result
34 | * Command execution result.
35 | */
36 | public CommandResult(String status, Serializable result) {
37 | this.status = status;
38 | this.result = new ObjectWrapper(result);
39 | }
40 |
41 | /**
42 | * Get command status.
43 | *
44 | * @return Command status.
45 | */
46 | public String getStatus() {
47 | return status;
48 | }
49 |
50 | /**
51 | * Get command execution result.
52 | *
53 | * @return Command execution result.
54 | */
55 | public Serializable getResult() {
56 | return result;
57 | }
58 |
59 | @Override
60 | public int describeContents() {
61 | return 0;
62 | }
63 |
64 | @Override
65 | public void writeToParcel(Parcel dest, int flags) {
66 | dest.writeString(status);
67 | dest.writeSerializable(result.getObject());
68 | }
69 |
70 | public static Parcelable.Creator CREATOR = new Parcelable.Creator() {
71 |
72 | @Override
73 | public CommandResult[] newArray(int size) {
74 | return new CommandResult[size];
75 | }
76 |
77 | @Override
78 | public CommandResult createFromParcel(Parcel source) {
79 | return new CommandResult(source.readString(),
80 | source.readSerializable());
81 | }
82 | };
83 | }
84 |
--------------------------------------------------------------------------------
/examples/Glass_PhillipsHue/glass_app/src/com/dataart/android/devicehive/client/commands/GetDeviceNotificationsCommand.java:
--------------------------------------------------------------------------------
1 | package com.dataart.android.devicehive.client.commands;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | import com.dataart.android.devicehive.Notification;
7 |
8 | /**
9 | * Get all device {@link Notification}s starting from given timestamp. This
10 | * request returns immediately regardless of whether there have been any
11 | * notifications since given timestamp or not. As a result returns list of
12 | * {@link Notification}.
13 | */
14 | public class GetDeviceNotificationsCommand extends NotificationsRetrivalCommand {
15 |
16 | private final String deviceId;
17 |
18 | /**
19 | * Construct a new command.
20 | *
21 | * @param deviceId
22 | * Device identifier.
23 | * @param lastNotificationPollTimestamp
24 | * Timestamp which defines starting point in the past for
25 | * notifications.
26 | */
27 | public GetDeviceNotificationsCommand(String deviceId,
28 | String lastNotificationPollTimestamp) {
29 | super(lastNotificationPollTimestamp);
30 | this.deviceId = deviceId;
31 | }
32 |
33 | @Override
34 | protected String getRequestPath() {
35 | String requestPath = String.format("device/%s/notification",
36 | encodedString(deviceId));
37 | if (lastNotificationPollTimestamp != null) {
38 | requestPath += "?start="
39 | + encodedString(lastNotificationPollTimestamp);
40 | }
41 | return requestPath;
42 | }
43 |
44 | @Override
45 | public void writeToParcel(Parcel dest, int flags) {
46 | dest.writeString(deviceId);
47 | super.writeToParcel(dest, flags);
48 | }
49 |
50 | public static Parcelable.Creator CREATOR = new Parcelable.Creator() {
51 |
52 | @Override
53 | public GetDeviceNotificationsCommand[] newArray(int size) {
54 | return new GetDeviceNotificationsCommand[size];
55 | }
56 |
57 | @Override
58 | public GetDeviceNotificationsCommand createFromParcel(Parcel source) {
59 | return new GetDeviceNotificationsCommand(source.readString(),
60 | source.readString());
61 | }
62 | };
63 | }
64 |
--------------------------------------------------------------------------------
/examples/wifi_config/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include