Initiate an action with Button A or B
-
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); }
-
if (M5.BtnA.wasPressed()) { ...... } M5.update();
-
Thanks for the reply
Found the tutorial too!
http://forum.m5stack.com/topic/42/lesson-2-buttons-menu