Plasmabol ESP8266 PWM frequentie.

byte outputPin = D4;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}

void loop() {
// put your main code here, to run repeatedly:
//todo: make a blacklist of misbehaving frequecies
long newFreq = random( 9, 20 );
long newDuration = random( 2048 );
long newDutyCycle = random( 6, 6 + PWMRANGE / 2 ) ;

analogWrite( outputPin, newDutyCycle );
analogWriteFreq( newFreq );
Serial.println( "duty: " + (String)newDutyCycle + " freq: " + (String)newFreq );
delay( newDuration );
}

ESP8266 – Gebufferd binair SPIFFS lezen. #2

270 KB/s.

De int bufferSize = 1460 is cruciaal, dit is nl de TCP hw buffer size.


void fileSend(String fileName) {
  if ( !SPIFFS.begin() ) {
    Serial.println("Fatal error: no SPIFFS disk present!");
    analogWrite(redLED, PWMRANGE);     
    while (true) {}   //wait forever
  }
  File thisFile = SPIFFS.open(fileName, "r");
  if (!thisFile) {
    webClient.print("HTTP/1.1 404 Not found\r\n\r\n");
    webClient.print("ERROR 404 - '" + fileName + "' was not found.");
    return;
  }
  //check the file's extention and tailor the header for that
  String httpHeader = "HTTP/1.1 200 \r\nContent-Type: text/plain\r\n";
  
  if ( fileName.substring(  fileName.length() - 4 ) == ".css" ) {
    httpHeader = "HTTP/1.1 200 \r\nContent-Type: text/css\r\n";
  }

  if ( fileName.substring(  fileName.length() - 4 ) == ".htm" || 
       fileName.substring(  fileName.length() - 4 ) == ".php" ) {
    httpHeader = "HTTP/1.1 200 \r\nContent-Type: text/html\r\n";
  }
  
  httpHeader += "Content-Length: " + (String)thisFile.size() + "\r\n\r\n" ;
  webClient.print(httpHeader);

  int bufferSize = 1460;
  char rwBuffer[bufferSize];
  while ( thisFile.available() > bufferSize ) {
    thisFile.readBytes(rwBuffer,bufferSize);  
    webClient.write(rwBuffer, bufferSize);
  }
  //send last chunk
  bufferSize = thisFile.available();
  thisFile.readBytes(rwBuffer,bufferSize);  
  webClient.write(rwBuffer, bufferSize);
  thisFile.close();
}//done