🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Initiate an action with Button A or B

    Scheduled Pinned Locked Moved M5 Stick/StickC
    3 Posts 2 Posters 5.8k Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      rbrakus
      last edited by rbrakus

      I would like to have it so a get request with arguments gets run when an action is made, for example pressing button A or B. I'm new with M5stickC and don't know how to do that.
      This is the code for sending a SMS with a delay... but executing a API call with a button is unknown for me...

       #include <M5StickC.h>
       #include <Arduino.h>
       #include <WiFi.h>
       #include <WiFiMulti.h>
       #include <HTTPClient.h>
       #define USE_SERIAL Serial
      
      WiFiMulti wifiMulti;
      
      void setup() {
      
      USE_SERIAL.begin(115200);
      
      USE_SERIAL.println();
      USE_SERIAL.println();
      USE_SERIAL.println();
      
      for(uint8_t t = 4; t > 0; t--) {
          USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
          USE_SERIAL.flush();
          delay(1000);
      }
      
      wifiMulti.addAP("xxxxx", "xxxxxx");
      
      }
      
      void loop() {
      // wait for WiFi connection
      if((wifiMulti.run() == WL_CONNECTED)) {
      
          HTTPClient http;
      
          USE_SERIAL.print("[HTTP] begin...\n");
          // configure traged server and url
      
            http.begin("https://api.46elks.com/a1/sms");
            http.addHeader("Content-Type", "application/x-www-form-urlencoded"); 
            http.setAuthorization("xxxxx", "xxxxxx");
            int httpCode = http.POST("from=+xxxxx&to=+xxxxxx&message=Hej");
      
      
          USE_SERIAL.print("[HTTP] GET...\n");
          // start connection and send HTTP header
           httpCode = http.GET();
      
          // httpCode will be negative on error
          if(httpCode > 0) {
              // HTTP header has been send and Server response header has been handled
              USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
      
              // file found at server
              if(httpCode == HTTP_CODE_OK) {
                  String payload = http.getString();
                  USE_SERIAL.println(payload);
              }
          } else {
              USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
          }
      
          http.end();
      }
      
      delay(10000);
      }
      
      m5stackM 1 Reply Last reply Reply Quote 0
      • m5stackM Online
        m5stack @rbrakus
        last edited by

        @rbrakus

          if (M5.BtnA.wasPressed()) {
                   ......
          }
          M5.update();
        
        1 Reply Last reply Reply Quote 1
        • R Offline
          rbrakus
          last edited by

          Thanks for the reply
          Found the tutorial too!
          http://forum.m5stack.com/topic/42/lesson-2-buttons-menu

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post