Merge branch 'IoTS-1.0.0-M1' of https://github.com/wso2/carbon-device-mgt-plugins into IoTS-1.0.0-M1

Conflicts:
	components/device-mgt-iot-arduino/org.wso2.carbon.device.mgt.iot.arduino.mgt.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/arduino/service/util/ArduinoServiceUtils.java
	features/device-mgt-iot-digitaldisplay-feature/org.wso2.carbon.device.mgt.iot.digitaldisplay.feature/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.digital_display.type-view/type-view.hbs
Shabirmean 9 years ago
commit f0b12bab62

@ -41,6 +41,7 @@ import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.exception.AccessTokenException; import org.wso2.carbon.device.mgt.iot.exception.AccessTokenException;
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException; import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager; import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord;
import org.wso2.carbon.device.mgt.iot.util.ZipArchive; import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
import org.wso2.carbon.device.mgt.iot.util.ZipUtil; import org.wso2.carbon.device.mgt.iot.util.ZipUtil;
@ -219,7 +220,7 @@ public class ArduinoService {
} }
try { try {
switch (protocolString) { /*switch (protocolString) {
case HTTP_PROTOCOL: case HTTP_PROTOCOL:
String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
if (deviceHTTPEndpoint == null) { if (deviceHTTPEndpoint == null) {
@ -235,7 +236,14 @@ public class ArduinoService {
default: default:
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
return; return;
}*/
String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
if (deviceHTTPEndpoint == null) {
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
return;
} }
ArduinoServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, callUrlPattern, true);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Failed to send switch-bulb request to device [" + deviceId + "] via " + protocolString); log.error("Failed to send switch-bulb request to device [" + deviceId + "] via " + protocolString);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
@ -244,6 +252,65 @@ public class ArduinoService {
response.setStatus(Response.Status.OK.getStatusCode()); response.setStatus(Response.Status.OK.getStatusCode());
} }
/**
* @param owner
* @param deviceId
* @param protocol
* @param response
* @return
*/
@Path("controller/readtemperature")
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Feature( code="readtemperature", name="Temperature", type="monitor",
description="Request temperature reading from Arduino agent")
public SensorRecord requestTemperature(@HeaderParam("owner") String owner,
@HeaderParam("deviceId") String deviceId,
@HeaderParam("protocol") String protocol,
@Context HttpServletResponse response) {
SensorRecord sensorRecord = null;
DeviceValidator deviceValidator = new DeviceValidator();
try {
if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId,
ArduinoConstants.DEVICE_TYPE))) {
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
}
} catch (DeviceManagementException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
String protocolString = protocol.toUpperCase();
if (log.isDebugEnabled()) {
log.debug(
"Sending request to read raspberrypi-temperature of device [" + deviceId + "] via " +
protocolString);
}
try {
String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
if (deviceHTTPEndpoint == null) {
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
}
String temperatureValue = ArduinoServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint,
ArduinoConstants
.TEMPERATURE_CONTEXT,
false);
SensorDataManager.getInstance().setSensorRecord(deviceId, ArduinoConstants.SENSOR_TEMPERATURE,
temperatureValue,
Calendar.getInstance().getTimeInMillis());
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId,
ArduinoConstants.SENSOR_TEMPERATURE);
} catch (DeviceManagementException | DeviceControllerException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
response.setStatus(Response.Status.OK.getStatusCode());
return sensorRecord;
}
/** /**
* @param dataMsg * @param dataMsg

@ -129,7 +129,7 @@ public class ArduinoServiceUtils {
public static boolean sendCommandViaMQTT(String deviceOwner, String deviceId, String resource, public static boolean sendCommandViaMQTT(String deviceOwner, String deviceId, String resource,
String state) throws DeviceManagementException { String state) throws DeviceManagementException {
boolean result; /*boolean result;
DeviceController deviceController = new DeviceController(); DeviceController deviceController = new DeviceController();
try { try {
@ -139,7 +139,8 @@ public class ArduinoServiceUtils {
log.error(errorMsg); log.error(errorMsg);
throw new DeviceManagementException(errorMsg, e); throw new DeviceManagementException(errorMsg, e);
} }
return result; return result;*/
return false;
} }
/* --------------------------------------------------------------------------------------- /* ---------------------------------------------------------------------------------------

@ -56,7 +56,6 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@API( name="arduino", version="1.0.0", context="/arduino")
@DeviceType( value = "arduino") @DeviceType( value = "arduino")
public class ArduinoService { public class ArduinoService {

@ -31,7 +31,7 @@
<!--publish to apim--> <!--publish to apim-->
<context-param> <context-param>
<param-name>managed-api-enabled</param-name> <param-name>managed-api-enabled</param-name>
<param-value>true</param-value> <param-value>false</param-value>
</context-param> </context-param>
<context-param> <context-param>
<param-name>managed-api-owner</param-name> <param-name>managed-api-owner</param-name>

@ -1,279 +1,95 @@
<div class="col-lg-12 margin-top-double"> {{#zone "topCss"}}
<h1 class="grey ">Arduino</h1> <style>
<hr> .thumbnail.icon:before {
<p class="margin-bottom-double light-grey ">Connect your Arduino device to the WSO2 IoT Server.</p> padding-top: 0;
</div> }
</style>
{{/zone}}
<div class="col-xs-12 col-sm-4 col-md-4 col-lg-4 padding-top"> {{#zone "device-thumbnail"}}
<img src="{{@unit.publicUri}}/images/ardunio-icon.png" class="img-responsive"> <img src="{{@unit.publicUri}}/images/ardunio-icon.png" class="img-responsive">
</div> {{/zone}}
<div class="col-xs-12 col-sm-8 col-md-8 col-lg-8 padding-top">
<h3 class="uppercase">What You Need</h3>
<hr>
<p class="grey margin-top">You'll need the following "Hardware":</p>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">ITEM 01</span>&nbsp;&nbsp;&nbsp;Arduino UNO Board.
</li>
<li class="padding-top-double"><span class="circle">ITEM 02</span>&nbsp;&nbsp;&nbsp;Adafruit Wifi-Sheild for
Arduino.
</li>
<li class="padding-top-double"><span class="circle">ITEM 03</span>&nbsp;&nbsp;&nbsp;An LED Bulb connected to Pin
13. <i>(If not available, will use the one on
the board.)</i>
</li>
<li class="padding-top-double"><span class="circle">GO-TO PREPARE</span></li>
</ul>
<br>
<a href="/api-store/apis/info?name={{@uriParams.deviceType}}&version=1.0.0&provider=admin"
class="btn-operations" target="_blank"><i class="fw fw-api"></i> View API</a>
<a href="#" class="download-link btn-operations"><i class="fw fw-download"></i>Download Sketch</a>
<div id="download-device-modal-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 center-container">
<h3>Name your device and download the agent from following link.</h3>
<br/>
<form id="downloadForm" method="GET" action="{{@app.context}}/api/devices/sketch/download"> {{#zone "device-opetations"}}
<div class="control-group"> <div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">
<div class="controls"> Operations
<input class="new-device-name" style="color:#3f3f3f;padding:5px"
type="text"
placeholder="Ex. Home_Arduino"
name="deviceName" size="60" required>
<br/><br/>
<input type="hidden" class="deviceType" name="deviceType"
value="{{@uriParams.deviceType}}"/>
<input type="hidden" class="sketchType" name="sketchType"
value="{{@uriParams.deviceType}}"/> &nbsp;&nbsp;
</div>
</div>
<div class="buttons" style="padding-bottom: 0px">
<a class="btn btn-operations" onclick="downloadAgent()">
Download Now
</a>
</div>
</form>
</div>
</div>
</div>
</div> </div>
<div class="add-margin-top-4x">
<div id="device-400-content" class="hide"> {{unit "iot.unit.device.operation-bar" device=device}}
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h3>Exception at backend. Try Later.</h3>
<div class="buttons">
<a href="#" id="device-400-link" class="btn-operations">
OK
</a>
</div>
</div>
</div>
</div>
</div> </div>
{{/zone}}
<div id="device-401-content" class="hide"> {{#zone "device-detail-properties"}}
<div class="modal-content"> <div class="media">
<div class="row"> <div class="media-left col-xs-12 col-sm-2 col-md-2 col-lg-2">
<div class="col-md-7 col-centered center-container"> <ul class="list-group" role="tablist">
<h3>You have to log in first.</h3><br/> <li class="active"><a class="list-group-item" href="#device_statistics" role="tab"
data-toggle="tab" aria-controls="device_statistics">Device
<div class="buttons"> Statistics</a>
<a href="#" id="device-401-link" class="blue-button"> </li>
Goto Login Page <li><a class="list-group-item" href="#policy_compliance" role="tab"
</a>&nbsp;&nbsp; data-toggle="tab" aria-controls="policy_compliance">Policy Compliance</a>
<a href="#" onclick="hidePopup();" class="btn-operations"> </li>
Cancel <li><a class="list-group-item" href="#event_log" role="tab" data-toggle="tab"
</a> aria-controls="event_log">Operations Log</a></li>
</div> </ul>
</div>
</div>
</div> </div>
</div> <div class="media-body add-padding-left-5x remove-padding-xs tab-content">
<div class="panel-group tab-content">
<div id="device-403-content" class="hide"> <div class="panel panel-default tab-pane active"
<div class="modal-content"> id="device_statistics" role="tabpanel" aria-labelledby="device_statistics">
<div class="row"> <div class="panel-heading">Device Statistics</div>
<div class="col-md-7 col-centered center-container"> {{unit "iot.unit.device.stats" device=device}}
<h3>Action not permitted.</h3><br/>
<div class="buttons">
<a href="#" id="device-403-link" class="btn-operations">
OK
</a>
</div>
</div> </div>
</div>
</div>
</div>
<div id="device-409-content" class="hide"> <div class="panel panel-default tab-pane" id="policy_compliance" role="tabpanel"
<div class="modal-content"> aria-labelledby="policy_compliance">
<div class="row"> <div class="panel-heading">Policy Compliance <span><a href="#"
<div class="col-md-7 col-centered center-container"> id="refresh-policy"><i
<h3>Device Sketch does not exist.</h3><br/> class="fw fw-refresh"></i></a></span></div>
<div class="panel-body">
<div class="buttons"> <div id="policy-spinner" class="wr-advance-operations-init hidden">
<a href="#" id="device-409-link" class="btn-operations"> <br>
OK &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</a> <i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading Policy Compliance . . .
<br>
<br>
</div>
<div id="policy-list-container">
<div class="panel-body">
Not available yet
</div>
<br class="c-both"/>
</div>
</div> </div>
</div> </div>
</div> <div class="panel panel-default tab-pane" id="event_log" role="tabpanel"
</div> aria-labelledby="event_log">
</div> <div class="panel-heading">Operations Log <span><a href="#"
id="refresh-operations"><i
<div id="device-unexpected-error-content" class="hide"> class="fw fw-refresh"></i></a></span></div>
<div class="modal-content"> <div class="panel-body">
<div class="row"> <div id="operations-spinner" class="wr-advance-operations-init hidden">
<div class="col-md-7 col-centered center-container"> <br>
<h3>Unexpected error.</h3><br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<i class="fw fw-settings fw-spin fw-2x"></i>
<div class="buttons"> &nbsp;&nbsp;&nbsp;
<a href="#" id="device-unexpected-error-link" class="btn-operations"> Loading Operations Log . . .
OK <br>
</a> <br>
</div>
<div id="operations-log-container">
<div class="panel-body">
Not available yet
</div>
<br class="c-both"/>
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<br/><br/>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 padding-double grey-bg">
<h3 class="uppercase">Prepare</h3>
<hr>
<p class="grey margin-top">Get the Wifi-Sheild mounted onto the Arduino-UNO board and follow the steps: </p>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">01</span>&nbsp;&nbsp;&nbsp;Download the Arduino-Sketch from
the [Download] link above.
</li>
<li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;Unzip the downloaded
Arduino-Sketch and open the <i>"ArduinoBoardSketch.h"</i>
file.
</li>
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;Provide appropriate values for
<i>[WLAN_SSID]</i> and <i>[WLAN_PASS]</i> variables according to your network.
</li>
<li class="padding-top-double"><span class="circle">04</span>&nbsp;&nbsp;&nbsp;Burn the sketch onto your Arduino
board and let the program run.
</li>
<li class="padding-top-double">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span class="fw-stack fw-lg margin-right">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-right-arrow fw-stack-1x"></i>
</span>
&nbsp;&nbsp;&nbsp;The Arduino will publish its internal temperature to the WSO2-IoT-Server and its LED on
<i>PIN 13</i> can be controlled from our Device Management page.
</li>
</ul>
<br>
</div>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 padding-double">
<h3 class="uppercase">Try Out</h3>
<hr>
<p class="grey margin-top">WSO2-IoT Server provides Analytics and Real-Time Statistics of your device</p>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">01</span>&nbsp;&nbsp;&nbsp;You can view all your created
devices at our <a href="{{@app.context}}/devices">[Device
Management]</a>
page.
</li>
<li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;You can select any of your
created devices here and check for available
operations and monitor Real-Time data.
</li>
<li class="padding-top-double"><span class="circle">03</span>&nbsp;&nbsp;&nbsp;You can also view "Analytics" of
the data published to the IoT-Server by navigating
to the [Device-Analytics Page] from here.
</li>
</ul>
<br/>
<p class="grey margin-top">Click on the image to zoom</p>
<center>
<a href="{{@unit.publicUri}}/images/myDevices_analytics.png" target="_blank">
<img src="{{@unit.publicUri}}/images/myDevices_analytics.png" class="img-responsive">
</a>
</center>
</div>
{{#zone "topCss"}}
<style type="text/css">
.circle {
background: none repeat scroll 0 0 #191919;
border-radius: 50px;
height: 50px;
padding: 10px;
width: 50px;
color: #fff;
}
.padding-top-double {
padding-top: 20px;
}
.padding-double {
padding: 20px;
}
.grey {
color: #333;
}
hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #7f7f7f;
margin: 1em 0;
padding: 0;
opacity: 0.2;
}
.light-grey {
color: #7c7c7c;
}
.uppercase {
text-transform: uppercase;
}
.grey-bg {
background-color: #f6f4f4;
}
</style>
{{/zone}}
{{#zone "bottomJs"}}
{{js "/js/download.js"}}
{{js "/js/jquery.validate.js"}}
<script type="text/javascript">
$(document).ready(function () {
toggleEnrollment();
});
function toggleEnrollment() {
$(".modalpopup-content").html($("#qr-code-modal").html());
//generateQRCode(".modalpopup-content .qr-code");
//showPopup();
}
</script>
{{/zone}} {{/zone}}
Loading…
Cancel
Save