Flic Home

    Community

    • Login
    • Search
    • Popular
    • Users
    1. Home
    2. mikaps7
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 1
    • Best 0
    • Controversial 0
    • Groups 0

    mikaps7

    @mikaps7

    0
    Reputation
    4
    Profile views
    1
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    mikaps7 Unfollow Follow

    Latest posts made by mikaps7

    • GET and POST variable

      When clicking the flic button, I want to have an HTTP makeRequest GET function, save some of the information in a global variable, and use this variable in an HTTP makeRequest POST function.

      I am able to create a variable and change it during the GET function. However, the information is not saved and when I use the POST function, it uses the value the variable had during the initialization phase.

      This is the code:
      var runNumber = -1 // my global variable

      buttonManager.on("buttonSingleOrDoubleClickOrHold", function(obj) {
      var button = buttonManager.getButton(obj.bdaddr);
      var clickType = obj.isSingleClick ? "click" : obj.isDoubleClick ? "double_click" : "hold";

      http.makeRequest({
      	url: urlGet,
      	method: "GET",
      	headers: {"Content-Type": "application/json"},
      }, function(err, res) {
      	console.log("request status: " + res.statusCode);
      	runNumber = 5 // changing the variable
      });
      	
      http.makeRequest({
      	url: urlPost,
      	method: "POST",
      	headers: {"Content-Type": "application/json"},
      	content: JSON.stringify({"Units":15, "Run Number":runNumber}),		
      }, function(err, res) {
      	console.log("request status: " + res.statusCode);
      });
      

      The code above is not working the way I expected it to work. The run number in the post function stays -1 although I change it to 5 in the get function.

      Please advise and thank you 🙂

      posted in Flic Hub SDK http request
      mikaps7
      mikaps7