I am trying to use an ESP32-C6-MINI to give my STM32 internet connectivity so it can post engineering data (think motor speed, current, etc.) to an online database that uses REST API. I programmed the ESP with the released ESP-AT firmware.
For testing I have been using the ESP32 C6 devkit and the free restdb.io website. Below is working Python code to accomplish the posting of a speed value. This was run on my PC -
Code: Select all
import requests
import json
url = "https://test1-dec1.restdb.io/rest/pumpdata"
payload = json.dumps( {"speed": "23000"} )
headers = {
'content-type': "application/json",
'x-apikey': "xxxxxxxxx",
'cache-control': "no-cache"
}
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text)
print(response.url)
Code: Select all
AT+HTTPCLIENT=2,1,"https://catfact.ninja/fact",,,2- Sending the request headers within the HTTPCLient command -
Code: Select all
AT+HTTPCLIENT=3,1,"https://test1-dec1.restdb.io/rest/pumpdata",,,2,"\"speed\": \"20\"","\"x-apikey\": \"919f6959b41e9a573fdfa4181b783cbf7bd19\"","\"cache-control\": \"no-cache\""- Sending the request headers with the HTTPCHEAD command then sending the GET or POST separately --
Code: Select all
AT+HTTPCHEAD=47 \"x-apikey\": \"919f6959b41e9a573fdfa4181b783cbf7bd19\" AT+HTTPCHEAD=27 \"cache-control\": \"no-cache\" AT+HTTPCLIENT=2,1"https://test1-dec1.restdb.io/rest/pumpdata",,,2 - sending as a HTTPCPOST command --
Code: Select all
AT+HTTPCPOST="https://test1-dec1.restdb.io/rest/pumpdata",110,3,"content-type: application/json","x-apikey: 919f6959b41e9a573fdfa4181b783cbf7bd19","cache-control: no-cache"
I found the user guide confusing. And am new to HTTPS so that is making things difficult. Am i missing something? If anyone has any feedback or tips, that would be appreciated. Thanks! - Sending the request headers with the HTTPCHEAD command then sending the GET or POST separately --
