• co

    g.clear();
    g.drawString("Fetching time...", 120, 120);
    
    Bangle.http("https://worldtimeapi.org/api/ip").then(data => {
      let time = JSON.parse(data).datetime.split("T")[1].split(".")[0];
      g.clear();
      g.drawString("Time: " + time, 120, 120);
    }).catch(err => {
      g.clear();
      g.drawString("Error: " + err, 120, 120);
    });
    

    Uncaught Error: Function "http" not found!
    at line 1 col 8
    Bangle.http("https://worldtimeapi.org/api/ip").then(data => ...

       ^
    

    thankss

  • Here's the documentation on http requests: https://www.espruino.com/Gadgetbridge#http-requests

  • Bangle.http is part of the Android integration app: https://thyttan.github.io/BangleApps/?id=android (see "Read more...")

  • What you're missing here is that you're doing JSON.parse(data) and not JSON.parse(data.resp)

    This works great though:

    Bangle.http("https://worldtimeapi.org/api/ip").then(data => {
      let time = JSON.parse(data.resp).datetime.split("T")[1].split(".")[0];
      g.clear();
      g.drawString("Time: " + time, 120, 120);
    }).catch(err => {
      g.clear();
      g.drawString("Error: " + err, 120, 120);
    });
    

    An in the other 7 posts you made about this - it really helps to use the remote debugging for this so you can see what's going on: https://www.espruino.com/Gadgetbridge#remote-debugging

  • thx,

    ---------END, below is not reply but a share, thx

    btw, if anyone interested,
    yesterday and even today GPT suggest to use data and not data.resp.

    however after i feed the example codelet (which yesterday i also feed to it),
    it now suggest the data.resp way.

    my experiences is, if the AI dont work for 1 time, repeat asking the same several times,
    then it may work.
    and stop using AI if the hurdles out weight the benefits.


    Bangle.http("https://pur3.co.uk/hello.txt").then(data=>{
    console.log("Got ",data);
    });

    --------- v the discuss below

    https://chatgpt.com/share/67125689-9d30-800f-a176-7f05f1b9e621

    ps: i independently feed the correct and then wrong code to it. at first it still wrong and suggest data,
    but after i feed the codelet, it reflects on itself and say should use data.resp as Gordon suggsted.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Can the webIDE use Bangle.http function? it didn't work.

Posted by Avatar for ccchan @ccchan

Actions