• I'm currently working on getting my bangle js to send a post request to a webserver and then after a period of time, submit a get request to the webserver, to the retreive the result the first post would cause.

    I've tried running a test script to confirm the watch is picking up the get data but I can't get it to display the output onto the screen.

    Below is the test script I'm running which I believe should work. Also I've added the getabridge debud logs which (as I understand them) confirm I am at least getting the data from the 'get' request.

    Is there an issue with my code approach to getting the output to return correctly, or is there something else I may have missed in the documentation that I need to be doing?

    Apologies if it's something to do with the Promie resolution. Still trying to get my head around async functions.

    const credentials = btoa(`${username}:${password}`);
    
    function getPost() {
      return new Promise((resolve, reject) => {
        Bangle.http(
          serverUrl,
          {
            method: 'GET',
            headers: {
            'Authorization': `Basic ${credentials}`
          }
        }, (err, response) => {
          if (err) {
            console.error("Error received:", err);
            reject(err);
          } else {
            console.log("Response received:", response);
            resolve(response);
          }
        });
      });
    }
    
    function swipeHandler(LR, UD) {
      if (LR === -1) {
    
        getPost().then(response => {
          g.clearRect(0, 0, g.getWidth(), g.getHeight()); 
          g.setFont('Vector', 20);
          g.drawString(response, 10, 40); 
    
        }).catch(error => {
          console.error("Error handling swipe:", error);
          g.clearRect(0, 0, g.getWidth(), g.getHeight()); 
          g.setFont('Vector', 20);
          g.drawString("fail", 10, 40); 
        });
    
      }
    }
    
    Bangle.on('swipe', swipeHandler);
    

    {"t":"http","url":"https://url.co.uk","id":"18650623373","method":"GET","headers":{"Authorization":"Basic
    "}}

    ================================================ SENDING ^PGB({"t":"http","id":"18650623373","resp":"data received"})

    ================================================

About

Avatar for Guptilious @Guptilious started