Comments (6)
async client is a client which connects asynchronously. when you read the data you can read them by small buffers and do other things in between
from wifiesp.
Do you have a sample code which can help me know it?
This is my current code.
#include <TMRpcm.h>
#include "WiFiEsp.h"
// Emulate EspSerial on pins 2/3 if not present
#ifndef HAVE_HWEspSerial
#include "SoftwareSerial.h"
SoftwareSerial EspSerial(7, 8); // RX, TX
#endif
//WiFiEspClient client;
WiFiEspClient client;
TMRpcm audio;
int file_number = 0;
static int len = 0;
#define CLIENT_BUFFER_SIZE 150 // Adjust this buffer size according to your needs
int buttonState = 0;
//1float flow; //Liters of passing water volume
//1unsigned long pulse_freq;
#define SD_CSPin 4
// delay function for with serial log.
void wait_min() {
int count = 0;
int secs = 30;
while (1) {
//Serial.print('.');
delay(1000);
count++;
if (count == secs) {
count = 0;
break;
}
}
//Serial.println();
return ;
}
void setup() {
// initialize serial for debugging
SD.begin(SD_CSPin);
Serial.begin(9600);
//Sets up the pins
pinMode(A0, INPUT);
pinMode(3, OUTPUT);
pinMode(6, INPUT_PULLUP);
//1 pinMode(2, INPUT);
//1 attachInterrupt(0, pulse, RISING); // Setup Interrupt
// //Serial.println(F("loading... SD card"));
// if (!SD.begin(SD_CSPin)) {
// //Serial.println(F("An Error has occurred while mounting SD"));
// }
// else {
// //Serial.println(F("SD card loaded"));
// }
// while (!SD.begin(SD_CSPin)) {
// //Serial.print(F("."));
// delay(500);
// }
// initialize serial for ESP module
EspSerial.begin(9600);
// initialize ESP module
WiFi.init(&EspSerial);
int status = 0; // the Wifi radio's status
// // attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
// Connect to WPA/WPA2 network
status = WiFi.begin("ACT103700825351", "25851250");
}
audio.CSPin = SD_CSPin;
//audio.speakerPin = 3;
}
void loop() {
buttonState = digitalRead(6);
char fileSlNum[3] = "";
itoa(file_number, fileSlNum, 10);
char file_name[10] = "";
strcat(file_name, "spy");
strcat(file_name, fileSlNum);
strcat(file_name, ".wav");
if (buttonState == LOW) {
//1 pulse_freq = 0;
//1 char dataString[20] = "";
Serial.println("In loop");
char fileSlNum[3] = "";
itoa(file_number, fileSlNum, 10);
char file_name[10] = "";
strcat(file_name, "spy");
strcat(file_name, fileSlNum);
strcat(file_name, ".wav");
//Serial.print("New File Name: ");
//Serial.println(file_name);
digitalWrite(3, HIGH);
audio.startRecording(file_name, 84000, A0);
//Serial.println("startRecording ");
// record audio for 2mins. means , in this loop process record 2mins of audio.
// if you need more time duration recording audio then
// pass higher value into the wait_min(int mins) function.
wait_min();
audio.stopRecording(file_name);
delay(1000);
Serial.println("Out");
//1 flow = .00225 * pulse_freq;
//Serial.println("stopRecording");
//1 Serial.println(flow);
//1 File dataFile = SD.open("dataset.csv", FILE_WRITE);
//1 strcat(dataString, file_name);
//1 strcat(dataString, ",");
//1 String data = dataString + String(flow);
//1 // if the file is available, write to it:
//1 if (dataFile) {
//1 dataFile.println(data);
//1 dataFile.close();
//1 // print to the serial port too:
//1 //Serial.println(dataString);
//1 }
//1 // if the file isn't open, pop up an error:
//1 else {
//1 //Serial.println("error opening datalog.txt");
//1 }
//1 pulse_freq = 0;
//}
// if (client.connect("192.168.0.104", 8000)) {
// //Serial.println(F("Start uploading..."));
// String start_request = "";
// String end_request = "";
// String filename="spy0.wav";
//
// start_request = start_request + "\n" + "------WebKitFormBoundaryuPbojkvQ2buPPB8a" + "\n" + "Content-Disposition: form-data; name=\"myfile\";filename="+filename+"\n" + "Content-Type: audio/wav" + "\n" + "\n";
// end_request = end_request + "\n" + "-------WebKitFormBoundaryuPbojkvQ2buPPB8a--" + "\n";
// len=len+start_request.length();
// len=len+end_request.length();
// client.println(F("POST /home HTTP/1.1"));
// client.println(F("Host: 192.168.0.104"));
// client.println(F("Content-Type: form-data; boundary=----WebKitFormBoundaryuPbojkvQ2buPPB8a"));
// client.print(F("Content-Length: "));
// client.println(String(len));
// client.print(start_request);
//
// File audio_file = SD.open("spy0.wav");
// if(audio_file){
// byte clientBuf[64];
// int clientCount =0;
// while(audio_file.available()){
// clientBuf[clientCount] = audio_file.read();
// clientCount++;
// if(clientCount>63){
// client.write(clientBuf,64);
// clientCount=0;
// }
// if(clientCount>0) client.write(clientBuf,clientCount);
// audio_file.close();
// }
// delay(1);
// client.println(end_request);
// client.stop();
// }
//
// //Serial.println(end_request);
// }
//audio.play("spy0.wav");
sendFileToServer(file_name);
digitalWrite(3, LOW);
file_number++;
}
}
void sendFileToServer(const char* fileName) {
Serial.println(fileName);
// String file;
// file+=String(fileName);
// Serial.println("In func");
// Serial.println(file);
// file.toUpperCase();
// Serial.println(file);
SD.begin(4);
File audioFile = SD.open(fileName);
if (!audioFile) {
Serial.println("Error opening file");
return;
}
// Connect to the server
if (client.connect("192.168.0.104", 8000)) {
Serial.println("Connected to server");
// Send HTTP headers
client.println(F("POST /simple_upload/ HTTP/1.1"));
client.print(F("Host: "));
client.println("192.168.0.104:8000");
client.println(F("Connection: close"));
client.println(F("Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"));
client.print(F("Content-Disposition: form-data; name=\"myfile\"; filename=\""));
client.print(fileName);
client.println(F("\""));
client.println(F("Content-Type: audio/wav")); // Set content type to audio/mpeg
client.println(F("Content-Transfer-Encoding: binary"));
client.print(F("Content-Length: "));
client.println(audioFile.size());
client.println();
// Serial.println(F("POST /simple_upload/ HTTP/1.1"));
// Serial.print(F("Host: "));
// Serial.println("192.168.0.104");
// //Serial.println(F("Connection: close"));
//
// Serial.print(F("Content-Disposition: form-data; name=\"myfile\"; filename=\""));
// Serial.print(fileName);
// Serial.println(F("\""));
// Serial.println(F("Content-Type: audio/wav")); // Set content type to audio/mpeg
// Serial.println(F("Content-Transfer-Encoding: binary"));
// Serial.print(F("Content-Length: "));
// Serial.println(audioFile.size());
// Serial.println();
// Serial.println(F("This is sending"));
// Serial.println(audioFile.size());
// Send the file content
uint8_t buf[CLIENT_BUFFER_SIZE]; // Buffer to read from SD card
size_t bytesRead;
// Send the file content
while ((bytesRead = audioFile.read(buf, sizeof(buf))) > 0) {
client.write(buf, bytesRead);
}
// End of the request
client.println();
client.println(F("------WebKitFormBoundary7MA4YWxkTrZu0gW--"));
audioFile.close();
//Serial.println(F("File sent"));
} else {
Serial.println(F("Connection failed"));
audioFile.close();
}
}
//1void pulse () // Interrupt function
//1{
//1 pulse_freq++;
//1}
from wifiesp.
Is it possible to use the wifi to transmit data in background?
from wifiesp.
Is it possible to use the wifi to transmit data in background?
the esp-01 does the WiFi and transmits the data over WiFi. so it is already in the background.
from wifiesp.
Ok, but what I am trying to ask is if I give 250kb of data to it can it be sent without waiting for it to complete?
As in the above code, I can record noise using tmrpcm without any interference. I can even run other code it will record in the background.
Is it possible to share data like that?
from wifiesp.
no
the Nano can't do it
from wifiesp.
Related Issues (20)
- How can I get data? HOT 5
- consumption time of an API (600ms) HOT 30
- UDP->remotePort() returns incorrect value HOT 3
- UDP link is not valid HOT 4
- REST API Post request to microsoft power bi real time data set HOT 1
- ESP8266 Crashes After UDP Packet Overload HOT 2
- ESP-Now with WiFiEsp library on ESP8266-01 interfaced to Arduino Uno HOT 2
- Connect to Firebase Database using WiFiESP
- The use of Delay() HOT 10
- TIMEOUT in same position every time on large HTTP header HOT 2
- WiFiEsp: Send Post message from Arduino Mega + ESP-01 issue HOT 8
- RingBuffer namespace collision with other libraries
- WebClient example doesn't work anymore
- Invalid "ClientSSL " connection directive HOT 5
- DDNS HOT 1
- Problem with the WebClientSSL example
- Can someone help with TMRpcm.h conflict HOT 1
- UDP + WiFiEspServer
- Hardware serial tutorial needed !! Help !! HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wifiesp.