Nodemcu making download and upload speed faster

Hello, guys. Me and my friend are uploading and downloading 8-bit 30000 raw sound data values between Lolin NODEMCU and MySql localhost database using XAMPP server. But uploading and especially downloading speed are very low than expected. How can we make download and upload speed faster between Wifi module and localhost? Can you help us? Sorry for the bad writing codes, we are just beginners :D. Also, I couldn't write raw sound datas because of character limit.

Here is the code for uploading data to localhost database.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <SPI.h>

const char* ssid = "*****";// 
const char* password = "*****";
//WiFiClient client;
char server[] = "******"; 
int sampleAmount=3000;
int i=0;
const PROGMEM byte sample1[]= 
{...};
const PROGMEM byte sample2[]= 
{....};  
const PROGMEM byte sample3[]=
{....}; 
const PROGMEM byte sample4[]=
{...}; 
const PROGMEM byte sample5[]=
{....}; 
const PROGMEM byte sample6[]=
{...};  
const PROGMEM byte sample7[]=
{...}; 
const PROGMEM byte sample8[]=
{...};
const PROGMEM byte sample9[]=
{...};  
const PROGMEM byte sample10[]=
{130,...,...}; 

WiFiClient client;   

void setup()
{
 Serial.begin(9600);
  delay(10);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.setOutputPower(20.5);
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
//  server.begin();
  Serial.println("Server started");
  Serial.print(WiFi.localIP());
  delay(1000);
  Serial.println("connecting...");
  client.setNoDelay(1);

 }
void loop(){
  if (client.connect(server, 80)){
      Serial.println("connected");     // Make a HTTP request:
      client.print("GET /multidata/multisample1.php?audiosample1=");
      HTTPRequest(pgm_read_byte(&sample1[i]));
      client.print("GET /multidata/multisample2.php?audiosample2=");
      HTTPRequest(pgm_read_byte(&sample2[i]));
      client.print("GET /multidata/multisample3.php?audiosample3=");
      HTTPRequest(pgm_read_byte(&sample3[i]));
      client.print("GET /multidata/multisample4.php?audiosample4=");
      HTTPRequest(pgm_read_byte(&sample4[i]));
      client.print("GET /multidata/multisample5.php?audiosample5=");
      HTTPRequest(pgm_read_byte(&sample5[i]));
      client.print("GET /multidata/multisample6.php?audiosample6=");
      HTTPRequest(pgm_read_byte(&sample6[i]));
      client.print("GET /multidata/multisample7.php?audiosample7=");
      HTTPRequest(pgm_read_byte(&sample7[i]));
      client.print("GET /multidata/multisample8.php?audiosample8=");
      HTTPRequest(pgm_read_byte(&sample8[i]));
      client.print("GET /multidata/multisample9.php?audiosample9=");
      HTTPRequest(pgm_read_byte(&sample9[i])); 
      client.print("GET /multidata/multisample10.php?audiosample10=");
      HTTPRequestLast(pgm_read_byte(&sample10[i]));
      if(i!=(sampleAmount-1)){
        i+=1;
        Serial.println(i);
        connectionRestarting();
      }
      else{
        endofUploading();
      }
     }
    } 
void HTTPRequest(byte sample){
      Serial.println(sample);
      client.print(sample);
      client.print(" ");      //SPACE BEFORE HTTP/1.1
      client.print("HTTP/1.1");
      client.println();
      client.println("Host: 192.168.1.106");
      client.println("Connection: keep-alive\r\n\r\n\r\n");
      client.println();
      
 }
void HTTPRequestLast(byte sample){
      Serial.println(sample);
      client.print(sample);
      client.print(" ");      //SPACE BEFORE HTTP/1.1
      client.print("HTTP/1.1");
      client.println();
      client.println("Host: 192.168.1.106");
      client.println("Connection: close");
      client.println();
 }
void connectionRestarting(){
        delayMicroseconds(100);
        WiFi.setOutputPower(20.5);
        WiFi.begin(ssid, password);



Here is the one of php file for uploading "sample1" array into "projectnew3" database created by us. We have done the same thing for other sample arrays.

<html>

<body>

<?php

$dbname = 'projectnew3';

$dbuser = 'root';  

$dbpass = '';

$dbhost = 'localhost';

$connect = @mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);

if(!$connect){

    echo "Error: " . mysqli_connect_error();

    exit();

}

echo "Connection Success!<br><br>";

$audiosample1 = $_GET["audiosample1"];

$query = "INSERT INTO srcn1 (audiosample1) VALUES ('$audiosample1')";

$result = mysqli_query($connect,$query);

echo "Insertion Success!<br>";

?>

</body>

</html>

Here is the code for downloading data from localhost database.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266HTTPClient.h>
#include "FS.h"


const char* ssid = "****"; //--> Your wifi name or SSID.
const char* password = "*****"; //--> Your wifi password.
WiFiClient wifiClient; 
IPAddress ip1 = ipaddr_addr("192.168.1.103");
IPAddress ip2 = ipaddr_addr("192.168.1.1");
IPAddress ip3 = ipaddr_addr("255.255.255.0");
IPAddress ip4 = ipaddr_addr("8.8.8.8");//dns 1
IPAddress ip5 = ipaddr_addr("8.8.4.4");//dns 2
const char *host = "*****";
String host2 = "*****";
HTTPClient http; //--> Declare object of class HTTPClient 
File file1;
File file2;
File file3;
File file4;
File file5;
File file6;
File file7;
File file8 ;
File file9 ;
File file10 ;
int id = 1;
int sampleAmount=100; 
void connectionRestarting();
void payloadGet(String GetAddress,String getData);
void endofFetching();

void setup() {
  Serial.begin(115200);
  SPIFFS.begin();
  File file1 = SPIFFS.open("/audiosample1.txt","w");
  File file2 = SPIFFS.open("/audiosample2.txt","w");
  File file3 = SPIFFS.open("/audiosample3.txt","w");
  File file4 = SPIFFS.open("/audiosample4.txt","w");
  File file5 = SPIFFS.open("/audiosample5.txt","w");
  File file6 = SPIFFS.open("/audiosample6.txt","w");
  File file7 = SPIFFS.open("/audiosample7.txt","w");
  File file8 = SPIFFS.open("/audiosample8.txt","w");
  File file9 = SPIFFS.open("/audiosample9.txt","w");
  File file10 = SPIFFS.open("/audiosample10.txt","w");
  delayMicroseconds(100);
  file1.println("OPEN");
  file2.println("OPEN");
  file3.println("OPEN");
  file4.println("OPEN");
  file5.println("OPEN");
  file6.println("OPEN");
  file7.println("OPEN");
  file8.println("OPEN");
  file9.println("OPEN");
  file10.println("OPEN");
  delayMicroseconds(100);
  file1.close();
  file2.close();
  file3.close();
  file4.close();
  file5.close();
  file6.close();
  file7.close();
  file8.close();
  file9.close();
  file10.close();
  delayMicroseconds(100);
  WiFi.mode(WIFI_OFF);
  WiFi.config(ip1,ip2, ip3,ip4,ip5);
  Serial.setTimeout(1);
  delay(5);
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  WiFi.setOutputPower(20.5);
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
//  server.begin();
  Serial.println("Server started");
  Serial.print(WiFi.localIP());
  delay(10);
  Serial.println("connecting...");
  wifiClient.setNoDelay(1);

}

void loop() {
  if (wifiClient.connect(host,80)){
  File file1 = SPIFFS.open("/audiosample1.txt","a");
  File file2 = SPIFFS.open("/audiosample2.txt","a");
  File file3 = SPIFFS.open("/audiosample3.txt","a");
  File file4 = SPIFFS.open("/audiosample4.txt","a");
  File file5 = SPIFFS.open("/audiosample5.txt","a");
  File file6 = SPIFFS.open("/audiosample6.txt","a");
  File file7 = SPIFFS.open("/audiosample7.txt","a");
  File file8 = SPIFFS.open("/audiosample8.txt","a");
  File file9 = SPIFFS.open("/audiosample9.txt","a");
  File file10 = SPIFFS.open("/audiosample10.txt","a");
  String GetAddress1,GetAddress2,GetAddress3,GetAddress4,GetAddress5,GetAddress6,GetAddress7,GetAddress8,GetAddress9,GetAddress10,getData;
  for(int i=1;i<=(sampleAmount);i++){
     getData = "ID=" + String(id);
     GetAddress1 = "http://ip_name/getData/getData1.php";
     file1=payloadGet(GetAddress1,getData,id,file1,file2,file3,file4,file5,file6,file7,file8,file9,file10);   
     GetAddress2 = "http://ip_name/getData/getData2.php";
     file2=payloadGet(GetAddress2,getData,id,file1,file2,file3,file4,file5,file6,file7,file8,file9,file10); 
     GetAddress3 = "http://ip_name/getData/getData3.php";
     file3=payloadGet(GetAddress3,getData,id,file1,file2,file3,file4,file5,file6,file7,file8,file9,file10); 
     GetAddress4 = "http://ip_name/getData/getData4.php";
     file4=payloadGet(GetAddress4,getData,id,file1,file2,file3,file4,file5,file6,file7,file8,file9,file10); 
     GetAddress5 = "http://ip_name/getData/getData5.php";
     file5=payloadGet(GetAddress5,getData,id,file1,file2,file3,file4,file5,file6,file7,file8,file9,file10); 
     GetAddress6 = "http://ip_name0/getData/getData6.php";
     file6=payloadGet(GetAddress6,getData,id,file1,file2,file3,file4,file5,file6,file7,file8,file9,file10); 
     GetAddress7 = "http://ip_name/getData/getData7.php";
     file7=payloadGet(GetAddress7,getData,id,file1,file2,file3,file4,file5,file6,file7,file8,file9,file10); 
     GetAddress8 = "http://ip_name/getData/getData8.php";
     file8=payloadGet(GetAddress8,getData,id,file1,file2,file3,file4,file5,file6,file7,file8,file9,file10); 
     GetAddress9 = "http://ip_name/getData/getData9.php";
     file9=payloadGet(GetAddress9,getData,id,file1,file2,file3,file4,file5,file6,file7,file8,file9,file10); 
     GetAddress10 = "http://ip_name/getData/getData10.php";
     file10=payloadGet(GetAddress10,getData,id,file1,file2,file3,file4,file5,file6,file7,file8,file9,file10);
     id+=1;     
     }
     file1.close();
     file2.close();
     file3.close();
     file4.close();
     file5.close();
     file6.close();
     file7.close();
     file8.close();
     file9.close();
     file10.close();
     endofFetching();
     }       
 else{
  connectionRestarting();
}
}
void connectionRestarting(){
  http.end(); //--> Close connection
  delayMicroseconds(1000);
  WiFi.config(ip1,ip2, ip3,ip4,ip5);
  WiFi.setOutputPower(20.5);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");
  Serial.println("WiFi connected");
  wifiClient.setNoDelay(1);
  Serial.println(WiFi.localIP());
}
File payloadGet(String GetAddress,String getData,int id,File file1,File file2,File file3,File file4,File file5,File file6,File file7,File file8,File file9,File file10){
   http.begin(wifiClient,GetAddress.c_str()); //--> Specify request destination
   http.addHeader("Content-Type", "application/x-www-form-urlencoded");    //Specify content-type header
   int httpCodeGet = http.POST(getData); //--> Send the request
   String payloadGet = http.getString(); //--> Get the response payload from server
   delayMicroseconds(1000);
   Serial.print("Returned data from Server : ");
   Serial.println(payloadGet); //--> Print request response payload
   if (payloadGet==""){
      WiFi.disconnect();
      WiFi.setAutoConnect(false);
      WiFi.mode(WIFI_OFF);
      wifiClient.setNoDelay(1);
      delayMicroseconds(100);
      connectionRestarting();
      }
   else{
      if(GetAddress=="http://192.168.1.106:80/getData/getData1.php"){
        file1.println(payloadGet);
        delayMicroseconds(1000);
        Serial.println(id);
        connectionRestarting();
        return file1;
      }
      else if(GetAddress=="http://192.168.1.106:80/getData/getData2.php"){
        file2.println(payloadGet);
        delayMicroseconds(1000);
        Serial.println(id);
        connectionRestarting();
        return file2;
      }
      else if(GetAddress=="http://192.168.1.106:80/getData/getData3.php"){
        file3.println(payloadGet);
        delayMicroseconds(1000);
        Serial.println(id);
        connectionRestarting();
        return file3;
      }
      else if(GetAddress=="http://192.168.1.106:80/getData/getData4.php"){
        file4.println(payloadGet);
        delayMicroseconds(1000);
        Serial.println(id);
        connectionRestarting();
        return file4;
      }
      else if(GetAddress=="http://192.168.1.106:80/getData/getData5.php"){
        file5.println(payloadGet);
        delayMicroseconds(1000);
        Serial.println(id);
        connectionRestarting();
        return file5;
      }
      else if(GetAddress=="http://192.168.1.106:80/getData/getData6.php"){
        file6.println(payloadGet);
        delayMicroseconds(1000);
        file6.close();
        Serial.println(id);
        connectionRestarting();
        return file6;
      }
      else if(GetAddress=="http://192.168.1.106:80/getData/getData7.php"){
        file7.println(payloadGet);
        delayMicroseconds(1000);
        Serial.println(id);
        connectionRestarting();
        return file7;
      }
      else if(GetAddress=="http://192.168.1.106:80/getData/getData8.php"){
        file8.println(payloadGet);
        delayMicroseconds(1000);
        Serial.println(id);
        connectionRestarting();
        return file8;
      }
      else if(GetAddress=="http://192.168.1.106:80/getData/getData9.php"){
        file9.println(payloadGet);
        delayMicroseconds(1000);
        Serial.println(id);
        connectionRestarting();
        return file9;
      }
      else if(GetAddress=="http://192.168.1.106:80/getData/getData10.php"){
        file10.println(payloadGet);
        delayMicroseconds(1000);
        Serial.println(id);
        connectionRestarting();
        return file10;
      }
       }
 }
void endofFetching(){
     Serial.println("Audio file has been fetched.");
     File filenew1 = SPIFFS.open("/audiosample1.txt","r");
     File filenew2 = SPIFFS.open("/audiosample2.txt","r");
     File filenew3 = SPIFFS.open("/audiosample3.txt","r");
     File filenew4 = SPIFFS.open("/audiosample4.txt","r");
     File filenew5 = SPIFFS.open("/audiosample5.txt","r");
     File filenew6 = SPIFFS.open("/audiosample6.txt","r");
     File filenew7 = SPIFFS.open("/audiosample7.txt","r");
     File filenew8 = SPIFFS.open("/audiosample8.txt","r");
     File filenew9 = SPIFFS.open("/audiosample9.txt","r");
     File filenew10 = SPIFFS.open("/audiosample10.txt","r");
     for(int i=0;i<=(sampleAmount-1);i++){
      Serial.write(filenew1.read());
         }
      filenew1.close();
      delay(10);
      Serial.println("");
      for(int i=0;i<=(sampleAmount-1);i++){
      Serial.write(filenew2.read());
         }
      filenew2.close();
      delay(10);
      Serial.println("");
      for(int i=0;i<=(sampleAmount-1);i++){
      Serial.write(filenew3.read());
         }
      filenew3.close();
      delay(10);
      Serial.println("");
      for(int i=0;i<=(sampleAmount-1);i++){
       Serial.write(filenew4.read());
         }
      filenew4.close();
      delay(10);
      Serial.println("");
      for(int i=0;i<=(sampleAmount-1);i++){
      Serial.write(filenew5.read());
         }
      filenew5.close();
      delay(10);
      Serial.println("");
      for(int i=0;i<=(sampleAmount-1);i++){
      Serial.write(filenew6.read());
         }
      filenew6.close();
      delay(10);
      Serial.println("");
      for(int i=0;i<=(sampleAmount-1);i++){
      Serial.write(filenew7.read());
         }
      filenew7.close();
      delay(10);
      Serial.println("");
      for(int i=0;i<=(sampleAmount-1);i++){
      Serial.write(filenew8.read());
         }
      filenew8.close();
      delay(10);
      Serial.println("");
      for(int i=0;i<=(sampleAmount-1);i++){
      Serial.write(filenew9.read());
         }
      filenew9.close();
      Serial.println("");
      for(int i=0;i<=(sampleAmount-1);i++){
      Serial.write(filenew10.read());
         }
      filenew10.close();
           
     
}




Here is the one of php file for downloading "sample1" array from"projectnew3" database created by us. We have done the same thing for other sample arrays.

<?php

  include 'database.php';

 

  if (!empty($_POST)) {

    $id=$_POST["ID"];

    $pdo = Database::connect();

    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $sql = 'SELECT * FROM srcn20 WHERE ID = ?';

   

    $q = $pdo->prepare($sql);

    $q->execute(array($id));

    $data = $q->fetch(PDO::FETCH_ASSOC);

    Database::disconnect();

   

    echo $data['audiosample20'];

  }

?>


That is the "database.php".

<?php

    class Database {

        private static $dbName = 'projectnew3' ;

        private static $dbHost = 'localhost' ;

        private static $dbUsername = 'root';

        private static $dbUserPassword = '';

         

        private static $cont  = null;

         

        public function __construct() {

            die('Init function is not allowed');

        }

         

        public static function connect() {

          // One connection through whole application

          if ( null == self::$cont ) {    

        try {

          self::$cont =  new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);

        }

        catch(PDOException $e) {

          die($e->getMessage());

        }

          }

          return self::$cont;

        }

         

        public static function disconnect() {

            self::$cont = null;

        }

    }

?>

Welcome to the forum

Your topic was MOVED to its current forum category as it is more suitable than the original

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

When you posted your code without code tags did you receive a warning message ?

Sorry about that. I did not see the warning.

Thanks

You should have got a warning but there may be a problem with the forum settings

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.