Hi. I have an HTTP post Sketch that work for my ESP32 wifi project, however I’m trying to adapt the sketch to a Wio LTE. I can reach the server however it’s not creating any registry. Can someone help with the missing piece? Thanks
Esp 32 Sketch:
#include <WiFi.h>
#include <HTTPClient.h>
#include <M5Atom.h>
// Replace with your network credentials
const char* ssid = "Wifi XXXXX";
const char* password = "XXXXXXX";
// REPLACE with your Domain name and URL path or IP address with path
const char* serverName = "http://datalogger.equione.pt/post-esp-data-pos.php";
// Keep this API Key value to be compatible with the PHP code provided in the project page.
// If you change the apiKeyValue value, the PHP file /post-esp-data.php also needs to have the same key
String apiKeyValue = "YYYYYYY";
String apiKeyValue = "tPmAT5Ab3j7F9";
String sensor = "94:B9:7E:A8:E2:7C";
float temp_ambiente = 12.4;
float temp_interior = 5.6;
float voltage = 0.00;
float current = 0.00;
float power = 0.00;
float energy;
float frequency;
float pf;
void setup() {
// put your setup code here, to run once:
M5.begin();
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
delay(20);
}
void loop() {
// put your main code here, to run repeatedly:
//ENVIAR PARA SERVIDOR VIA WiFi
if(WiFi.status()== WL_CONNECTED){
HTTPClient http;
// Your Domain name with URL path or IP address with path
http.begin(serverName);
// Specify content-type header
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Prepare your HTTP POST request data
String httpRequestData = "api_key=" + apiKeyValue + "&sensor=" + sensor
+ "&ambiente=" + temp_ambiente + "&interior=" + temp_interior
+ "&voltagem=" + voltage + "&eragem=" + current + "&potencia=" + power + "";
Serial.print("httpRequestData: ");
Serial.println(httpRequestData);
// Send HTTP POST request
int httpResponseCode = http.POST(httpRequestData);
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
}
Wio LTE Sketch:
#include <WioLTEforArduino.h>
#include <stdio.h>
#define URL "http://datalogger.equione.pt/post-esp-data-pos.php"
#define APN "myconnection"
#define USERNAME ""
#define PASSWORD ""
String apiKeyValue = "tPmAT5Ab3j7F9";
String sensor = "94:B9:7E:A8:E2:7C";
float temp_ambiente = 12.4;
float temp_interior = 5.6;
float voltage = 0.00;
float current = 0.00;
float power = 0.00;
float energy;
float frequency;
float pf;
#define INTERVAL (10000)
WioLTE Wio;
// ---------------------------------------------------------------
void setup() {
SerialUSB.println("### I/O Initialize.");
Wio.Init();
SerialUSB.println("### Power supply ON.");
Wio.PowerSupplyLTE(true);
delay(500);
SerialUSB.println("### Turn on or reset.");
if (!Wio.TurnOnOrReset()) {
SerialUSB.println("### ERROR! ###");
return;
}
SerialUSB.println("### Connecting to \""APN"\".");
if (!Wio.Activate(APN, USERNAME, PASSWORD)) {
SerialUSB.println("### ERROR! ###");
return;
}
SerialUSB.println("### Setup completed.");
}
// ---------------------------------------------------------------
void loop() {
char data[200];
int status;
SerialUSB.println("### Post.");
sprintf(data, "api_key=%s&sensor=%s&ambiente=%.2f&interior=%.2f&voltagem=%.2f&eragem=%.2f&potencia=%.2f", apiKeyValue.c_str(), sensor.c_str(), temp_ambiente, temp_interior, voltage, current, power);
SerialUSB.print("Post:");
SerialUSB.print(data);
SerialUSB.println("");
if (!Wio.HttpPost(URL, data, &status)) {
SerialUSB.println("### ERROR! HttpPost ###");
}
else
{
SerialUSB.print("Status: ");
SerialUSB.println(status);
}
SerialUSB.println("### Wait.");
delay(INTERVAL);
}