Skip to content

Instantly share code, notes, and snippets.

@bkrajendra
Created March 7, 2015 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkrajendra/50e2b0081a6e9ed22889 to your computer and use it in GitHub Desktop.
Save bkrajendra/50e2b0081a6e9ed22889 to your computer and use it in GitHub Desktop.
onsenui ESP communication example
{"light":1,"light_status":"off","somedata":"Hello world!"}
var module = angular.module('app', ['onsen']);
module.controller("ESPController", function($http, $scope) {
$scope.switch1 = function() {
alert(lightSwtch.isChecked())
$http.get("a.txt")
.success(function(data) {
$scope.light = data.light;
$scope.light_status = data.light_status;
$scope.somedata = data.somedata;
})
.error(function(data) {
console.log("ERROR: " + data);
});
}
});
<!-- add this to any of ur <ons-page> tag -->
<ons-list modifier="inset" style="margin-top: 10px" ng-controller="ESPController">
<ons-list-item class="to-wrapper">
<ons-row class="" >
<ons-col width="60px" class="">
<ons-icon icon="{{light?'fa-bell-o':'fa-bell'}}" size="20px"></ons-icon>
</ons-col>
<ons-col>
<div class="">{{light_status}}</div>
<div class="">{{somedata}}</div>
</ons-col>
</ons-row>
</ons-list-item>
<ons-list-item>
Light
<ons-switch modifier="list-item" var="lightSwtch" ng-click="switch1()"></ons-switch>
</ons-list-item>
<ons-list-item>
Plug
<ons-switch modifier="list-item" checked></ons-switch>
</ons-list-item>
</ons-list>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment