Sample Guided Path App
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 18 commits ahead of sumeetkakkar:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
device
sampleapp
.gitignore
Procfile
README.md
manage.py
requirements.txt
runtime.txt

README.md

Sample Guided Path App

The main logic is in device/templates/index.html.

Following are the highlights:

  • Include SDK javascript //static.nexus.support.com/gpa/v1/nexusNavigator.js
<script type="text/javascript" src="//static.nexus.support.com/gpa/v1/nexusNavigator.js"></script>
  • Initialize the nexus api object
var nexusApi = null;
nexusNavigator.on('ready', function (api) {
  console.log("Nexus API is ready");
  nexusApi = api;
  onReady();
});
  • Load nexus style sheets (optional).
nexusNavigator.loadCss();
  • Get token for authentication. This token should be authenticated from a backend API. Backend authentication is desired because of security reasons.
    nexusApi.getToken(function(token){
      console.log("AuthenticateUser: Token received. Validating with server");
      var jqxhr = $.ajax( {
        type: "GET",
        url: "/device/authenticate/?token="+token
def authenticate(request):
.....
  token = request.GET["token"]
  headers = {'Accept': 'application/json', 'authorization': 'JWT ' + token}
.....  
  r = requests.get(serverUrl+"/api/v1/oauth2/verify", verify=False, headers=headers)
  if r.status_code == 400:
    return JsonResponse({"err":{"message":"Invalid Token"}})
  if r.status_code == 403:
    return JsonResponse({"err":{"message":"Authentication Failed"}})
  if r.status_code != 200:
    return JsonResponse({"err":{"message":"Server error"}})
  try:
    data = json.loads(r.text)
  except:
    return JsonResponse({"err":{"message":"Error returned by authenticate"}})
  return JsonResponse(data)
    nexusApi.getSession(function(session){
      getSubscriberDevice(session.consumer, callback);
    });
  • Optionally, if there is a need to push commands to remote connected device over websocket channel, refer following code:
   // Invoked when nexus is connected to remote device over websocket channel. This is optional.
  nexusNavigator.on('task-init', function () {
    console.log("Nexus connected to remote device");
    getData();
  });
  
  // Optional commands can be pushed once the websocket channel is open with remote device. Ex:
      nexusApi.isConnected(function (yes) {
      if (yes) {
        //return getDeviceInfo();
        nexusApi.sendCommand("GET_SYSINFO",1,"getInfo",{},function(o) {
          done(null, o);
        });
      } else {
        console.log("Not connected!!!");
        done(new Error("Not Connected!!!"));
      }
    });