<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[HTTP POST from Arduino&#x2F;ESP8266&#x2F;ESP32 How to send parameters (x-www-form-urlencoded) using micropython!]]></title><description><![CDATA[<p dir="auto">I don't have ANY experience with micropython..but I would like to use blockly features of UI flow for development thus I would appreciate if anyone could help me out how to translate this simple http post with parameters into micropython?</p>
<pre><code>  http.begin("https://api.46elks.com/a1/sms");
  http.addHeader("Content-Type", "application/x-www-form-urlencoded"); 
  http.setAuthorization("XXXXX", "YYYYYY");
  int httpCode = http.POST("'from:+XXXXX','to:+XXXXX','message:Hej'");
</code></pre>
<p dir="auto">Here is the rest of the code! Thank you!</p>
<pre><code>#include &lt;M5StickC.h&gt;
#include &lt;Arduino.h&gt;
#include &lt;WiFi.h&gt;
#include &lt;WiFiMulti.h&gt;

#include &lt;HTTPClient.h&gt;

#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 &gt; 0; t--) {
    USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
    USE_SERIAL.flush();
    delay(1000);
}

wifiMulti.addAP("YYYY", "ZZZZZ");

}

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", "YYYYYY");
      int httpCode = http.POST("'from:+XXXXX','to:+XXXXX','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 &gt; 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);
}
</code></pre>
]]></description><link>https://community.m5stack.com/topic/1902/http-post-from-arduino-esp8266-esp32-how-to-send-parameters-x-www-form-urlencoded-using-micropython</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Apr 2026 11:00:43 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/1902.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 26 Apr 2020 21:22:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to HTTP POST from Arduino&#x2F;ESP8266&#x2F;ESP32 How to send parameters (x-www-form-urlencoded) using micropython! on Fri, 01 May 2020 07:24:36 GMT]]></title><description><![CDATA[<p dir="auto">My friend and colleague programmed this..</p>
<p dir="auto"><a href="https://github.com/46elks/46elks-getting-started/blob/master/code-examples/MicroPython/https_post_with_micropython.py" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/46elks/46elks-getting-started/blob/master/code-examples/MicroPython/https_post_with_micropython.py</a><br />
If you would like to use 46elks Telco API mentioned in the code, register <a href="https://46elks.com/register" target="_blank" rel="noopener noreferrer nofollow ugc">here</a> and contact us at <a href="mailto:help@46elks.com" target="_blank" rel="noopener noreferrer nofollow ugc">help@46elks.com</a> for help.</p>
<pre><code># Rudimentary HTTPS POST request using MicroPython without any 
 dependencies.
 # Supports Basic Auth and encodes data as x-www-form-urlencoded.
 #
 # Written by Johannes Ridderstedt &lt;johannesl@46elks.com&gt;
 # This code is public domain. Use freely.

 from ubinascii import b2a_base64
 import usocket
 import ussl
 
 # API credidentials
 username = 'u2c11ef65b429a8e16ccb1f960d02c734'
 password = 'C0ACCEEC0FAFE879189DD5D57F6EC348'
 
 def quote( value ):
   l = []
   for ch in value.encode( 'utf-8' ):
     if ch == b' ':
  l.append( b'+' )
elif ch &gt; 32 and ch &lt; 128 and ch not in b'?=':
  l.append( b'%c' % ch )
else:
  l.append( b'%%%02X' % ch )
   return b''.join( l )

 def api_post( path, data ):

   info = usocket.getaddrinfo( 'api.46elks.com', 443 )
   ip = info[0][-1]

   args = []
   for key in data:
args.append( quote( key ) + '=' + quote( data[key] ) )
   content = b'&amp;'.join( args )

   lines = [
b'POST /a1/%s HTTP/1.0' % path,
b'Authorization: Basic %s' % b2a_base64( username + ':' + password )[:-1],
b'Content-type: application/x-www-form-urlencoded',
b'Content-Length: %d' % len( content ),
b'',
content
   ]

   conn = usocket.socket()
   conn.connect( ip )
   conn = ussl.wrap_socket( conn )
   conn.write( b'\r\n'.join( lines ) )
   print( conn.read(4096).decode('utf-8') )
   conn.close()

 sms = {
   'to': '+46704508449',
   'from': 'MicroPython',
   'message': 'Hello from MicroPython!'
 }
 api_post( '/sms', sms )
</code></pre>
]]></description><link>https://community.m5stack.com/post/8455</link><guid isPermaLink="true">https://community.m5stack.com/post/8455</guid><dc:creator><![CDATA[rbrakus]]></dc:creator><pubDate>Fri, 01 May 2020 07:24:36 GMT</pubDate></item><item><title><![CDATA[Reply to HTTP POST from Arduino&#x2F;ESP8266&#x2F;ESP32 How to send parameters (x-www-form-urlencoded) using micropython! on Tue, 28 Apr 2020 18:18:01 GMT]]></title><description><![CDATA[<p dir="auto">I've been trying something similar and it appears to be impossible with uiflow. Recently saw someone had success with raw micropython</p>
]]></description><link>https://community.m5stack.com/post/8415</link><guid isPermaLink="true">https://community.m5stack.com/post/8415</guid><dc:creator><![CDATA[Thrasher]]></dc:creator><pubDate>Tue, 28 Apr 2020 18:18:01 GMT</pubDate></item></channel></rss>