🤖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

    M5 Stick/StickC
    2
    3
    5.1k
    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
      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
        m5stack @rbrakus
        last edited by

        @rbrakus

          if (M5.BtnA.wasPressed()) {
                   ......
          }
          M5.update();
        
        1 Reply Last reply Reply Quote 1
        • R
          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
          • First post
            Last post