been stuck on this for a week or so now.
am trying to get an audio sample from esp32 with and electric microphone(not boarded about quality yet).
the problem is i am trying to send the audio file to node-red by can send the full data cause i have a char size of (110) tried every other size above that and didn't get any output.
here's the code below.
Code: Select all
#include <PubSubClient.h>
#include <WiFi.h>
#include <WiFiClient.h>
const char* ssid = "";
const char* password = "";
const char* mqttServer = "";
const int mqttPort = 1883;
String str_payload;
WiFiClient espClient;
PubSubClient client(espClient);
void setup()
{
Serial.begin(9600);
WiFi.begin(ssid,password);
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
client.setServer(mqttServer, mqttPort);
while(!client.connected()) {
Serial.println("Connecting to MQTT...");
if(client.connect("ESP8266Client" )) {
Serial.println("connected");
}else{
Serial.print("failed state ");
Serial.print(client.state());
delay(2000);
}
}
vibrate();
my_analog();
}
void loop()
{
}
void vibrate(){
pinMode(2, OUTPUT);
digitalWrite(2,HIGH);
delay(2000);
digitalWrite(2,LOW);
my_record();
}
void my_record()
{
for(int y=0;y<11;y++)
{
for(int i=0;i<800;i++)
{
str_payload += char(analogRead(35)/4);
// Serial.println(str_payload.length());
}
my_print();
}
}
void my_analog()
{
if(digitalRead(2)==LOW)
{
my_record();
}
}
void my_print()
{
char buf[110];
// String str_payload = String(str_payload);
String (str_payload).toCharArray(buf,110);
Serial.print("publishing");
client.publish("test/esp8266",buf);
str_payload="";
// Serial.println(str_topic);
// Serial.println(buf);
Serial.println("finish");
}