Merge pull request #121 from NuwanSameera/IoTS-1.0.0-M1

Fixed Arduino operations and Ui problemes
Ruwan 9 years ago
commit c928732dd0

@ -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.DeviceControllerException;
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.ZipUtil;
@ -219,7 +220,7 @@ public class ArduinoService {
}
try {
switch (protocolString) {
/*switch (protocolString) {
case HTTP_PROTOCOL:
String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
if (deviceHTTPEndpoint == null) {
@ -235,7 +236,14 @@ public class ArduinoService {
default:
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
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) {
log.error("Failed to send switch-bulb request to device [" + deviceId + "] via " + protocolString);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
@ -244,6 +252,65 @@ public class ArduinoService {
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

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

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

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

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

@ -1,279 +1,95 @@
<div class="col-lg-12 margin-top-double">
<h1 class="grey ">Arduino</h1>
<hr>
<p class="margin-bottom-double light-grey ">Connect your Arduino device to the WSO2 IoT Server.</p>
</div>
{{#zone "topCss"}}
<style>
.thumbnail.icon:before {
padding-top: 0;
}
</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">
</div>
<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/>
{{/zone}}
<form id="downloadForm" method="GET" action="{{@app.context}}/api/devices/sketch/download">
<div class="control-group">
<div class="controls">
<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>
{{#zone "device-opetations"}}
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">
Operations
</div>
<div id="device-400-content" class="hide">
<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 class="add-margin-top-4x">
{{unit "iot.unit.device.operation-bar" device=device}}
</div>
{{/zone}}
<div id="device-401-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h3>You have to log in first.</h3><br/>
<div class="buttons">
<a href="#" id="device-401-link" class="blue-button">
Goto Login Page
</a>&nbsp;&nbsp;
<a href="#" onclick="hidePopup();" class="btn-operations">
Cancel
</a>
</div>
</div>
</div>
{{#zone "device-detail-properties"}}
<div class="media">
<div class="media-left col-xs-12 col-sm-2 col-md-2 col-lg-2">
<ul class="list-group" role="tablist">
<li class="active"><a class="list-group-item" href="#device_statistics" role="tab"
data-toggle="tab" aria-controls="device_statistics">Device
Statistics</a>
</li>
<li><a class="list-group-item" href="#policy_compliance" role="tab"
data-toggle="tab" aria-controls="policy_compliance">Policy Compliance</a>
</li>
<li><a class="list-group-item" href="#event_log" role="tab" data-toggle="tab"
aria-controls="event_log">Operations Log</a></li>
</ul>
</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="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h3>Action not permitted.</h3><br/>
<div class="buttons">
<a href="#" id="device-403-link" class="btn-operations">
OK
</a>
</div>
<div class="panel panel-default tab-pane active"
id="device_statistics" role="tabpanel" aria-labelledby="device_statistics">
<div class="panel-heading">Device Statistics</div>
{{unit "iot.unit.device.stats" device=device}}
</div>
</div>
</div>
</div>
<div id="device-409-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h3>Device Sketch does not exist.</h3><br/>
<div class="buttons">
<a href="#" id="device-409-link" class="btn-operations">
OK
</a>
<div class="panel panel-default tab-pane" id="policy_compliance" role="tabpanel"
aria-labelledby="policy_compliance">
<div class="panel-heading">Policy Compliance <span><a href="#"
id="refresh-policy"><i
class="fw fw-refresh"></i></a></span></div>
<div class="panel-body">
<div id="policy-spinner" class="wr-advance-operations-init hidden">
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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 id="device-unexpected-error-content" class="hide">
<div class="modal-content">
<div class="row">
<div class="col-md-7 col-centered center-container">
<h3>Unexpected error.</h3><br/>
<div class="buttons">
<a href="#" id="device-unexpected-error-link" class="btn-operations">
OK
</a>
<div class="panel panel-default tab-pane" id="event_log" role="tabpanel"
aria-labelledby="event_log">
<div class="panel-heading">Operations Log <span><a href="#"
id="refresh-operations"><i
class="fw fw-refresh"></i></a></span></div>
<div class="panel-body">
<div id="operations-spinner" class="wr-advance-operations-init hidden">
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading Operations Log . . .
<br>
<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>
<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}}

@ -15,10 +15,10 @@
<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;Raspberry Pi Board (Internet
Enabled [Wifi or Ethernet]).
Enabled [Wifi or Ethernet]).
</li>
<li class="padding-top-double"><span class="circle">ITEM 02</span>&nbsp;&nbsp;&nbsp;A Digital Display with HDMI
Cable.
Cable.
</li>
<li class="padding-top-double"><span class="circle">GO-TO PREPARE</span></li>
</ul>
@ -50,7 +50,7 @@
<div class="buttons" style="padding-bottom: 0px">
<a class="btn btn-operations" onclick="downloadAgent()">Download Now</a> &nbsp;&nbsp;
<a href="#" id="download-device-download-link" class="btn btn-operations"> Copy Link </a>
&nbsp;&nbsp;
&nbsp;&nbsp;
</div>
</form>
</div>
@ -164,15 +164,15 @@
<h3 class="uppercase">Prepare</h3>
<hr>
<p class="grey margin-top">Follow the steps to get your Digital-Display up &amp; running and communicating to the
WSO2 IoT-Server.</p>
WSO2 IoT-Server.</p>
<ul class="list-unstyled">
<li class="padding-top-double"><span class="circle">01</span>&nbsp;&nbsp;&nbsp;Connect a monitor to your
RaspberryPi via the HDMI cable to get the
Graphical-User-Interface of the RaspberryPi board.
RaspberryPi via the HDMI cable to get the
Graphical-User-Interface of the RaspberryPi board.
</li>
<li class="padding-top-double"><span class="circle">02</span>&nbsp;&nbsp;&nbsp;Setup the RaspberryPi to connect
to the internet (via Ethernet or Wifi) and
note-down its <i>IP_ADDRESS</i>.
to the internet (via Ethernet or Wifi) and
note-down its <i>IP_ADDRESS</i>.
</li>
</ul>
<br>
@ -196,17 +196,17 @@
<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.
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.
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.
the data published to the IoT-Server by navigating
to the [Device-Analytics Page] from here.
</li>
</ul>
<br/>
@ -222,51 +222,43 @@
<style type="text/css">
.circle {
background: none repeat scroll 0 0 #191919;
border-radius: 50px;
height: 50px;
padding: 10px;
width: 50px;
color: #fff;
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-top: 20px;
}
.padding-double {
padding: 20px;
padding: 20px;
}
.grey {
color: #333;
color: #333;
}
hr {
display: block;
height: 1px;
border: 0;
border-top: 1px solid #7f7f7f;
margin: 1em 0;
padding: 0;
opacity: 0.2;
display: block;
height: 1px;
border: 0;
border-top: 1px solid #7f7f7f;
margin: 1em 0;
padding: 0;
opacity: 0.2;
}
.light-grey {
color: #7c7c7c;
color: #7c7c7c;
}
.uppercase {
text-transform: uppercase;
text-transform: uppercase;
}
.grey-bg {
background-color: #f6f4f4;
background-color: #f6f4f4;
}
</style>
{{#zone "bottomJs"}}
{{js "/js/download.js"}}
{{js "/js/jquery.validate.js"}}
{{/zone}}
{{/zone}}
Loading…
Cancel
Save