Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
enriquecml
@enriquecml
hehe
Tejas H
@CodingCreate101
Thank you
enriquecml
@enriquecml
pair programming ?
haha
probonopd
@probonopd
hi all, is there a way to make server.onFileUpload upload to a fixed filename (instead of using what the client sends)?
  server.onFileUpload([](AsyncWebServerRequest * request, const String & filename, size_t index, uint8_t *data, size_t len, bool final) {
    if(!index){
      // filename="cache.gco" ; // Override what the client sent as the filename - DOES NOT WORK
    }
  });
I am using ESPAsyncWebServer by @me-no-dev
Victor Tseng
@Palatis
well that filename is the client tells you what file it sends
you get to decide where to store it.
for example user sends you C:\Users\Palatis\blah.jpg
and you can't modify it because it's a const String &.
probonopd
@probonopd
i know that the client sends it, but I want to override what the client sends
and if i leave away the "const" then it doesn't compile
Victor Tseng
@Palatis
you can't, that desicision is on the client.
probonopd
@probonopd
well, the client sends a name but the server can certainly ignore what the client sends
or wait, could i move the file after it is uploaded?
Victor Tseng
@Palatis
that filename is the filename from the client side
the file isn't saved anywhere
it's still in ram
read from data
probonopd
@probonopd
the file is saved to spiffs
in a file with a name
and i want to override that name of the file on spiffs
Martin Ayotte
@martinayotte
Simply not use the "filename" variable and provide another filename to SPIFFS calls.
Victor Tseng
@Palatis
i guess not
i mean, the file isn't saved directly to SPIFFS.
at least not what's written in lib code.
Martin Ayotte
@martinayotte
I understand that, it is up to user's code to call the SPIFFS functions
Victor Tseng
@Palatis
i'm answering @probonopd XD
Martin Ayotte
@martinayotte
:-)
Victor Tseng
@Palatis
if you're using the default SPIFFSEditor class
it does write the file to a temp file
but if not (since you want to handle the write yourself), then it's not stored anywhere by default.
received data is in data provided by onUpload()
as i search through the lib code, the only place which calls a write() is inside SPIFFSEditor
Victor Tseng
@Palatis
and the only place where SPIFFSEditor is used is inside example/ESP_AsyncFSBrowser
I guess you copy-pasted the example without modifying it to suite your needs.
probonopd
@probonopd
I copy-pasted the example and now I want to change it so that it does what I need...
Victor Tseng
@Palatis
yup, don't use that SPIFFSEditor, write your own handler.
cuz you want to do different things.
probonopd
@probonopd
ok, thanks
bidyutper
@bidyutper
Want to store temperature sensor data when there is no Mqtt broker means if I turnoff WiFi.Thus store sensor data publish over Mqtt connection whenever it's find WiFi network.
enriquecml
@enriquecml
@bidyutper you can use SPIFF System file or use RTCMemory for save data
paraflou
@paraflou

Hi.

I am using Async client to connect to philips hue bridge in order to send asynchornously PUT json messages to hue bridge so that i can change hue status and color.

Async client connects to hue bridge and after a few seconds it disconnects (onDisconnect is triggered).

What can i do?

Me No Dev
@me-no-dev
PUT means HTTP and HTTP runs single requests: connect, send, read, disconnect. It's not a connection that is open all of the time
paraflou
@paraflou
And how can i then use async client to make put requests in loop? Calling ::connect every time i want to send request is very slow.
paraflou
@paraflou
'''

'''

define BASE_HUE_URL "192.168.100.175"

define BASE_HUE_PORT 80

define PUT_HUE_URL "PUT /api/[hue bridge key]/lights/3/state HTTP/1.1\r\nHost: http://192.168.100.175\r\nUser-Agent: ESP8266HTTPClient\r\nContent-Type: application/json\r\nContent-Length: 11/r/n/r/n{\"on\":true}"

static AsyncClient * aClient = NULL;

void setup()
{
Serial.begin(115200);
Serial.setDebugOutput(true);

// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" ----- WiFi Connected -----");
WiFi.macAddress(mac);
Serial.print("MAC: ");
Serial.print(mac[0], HEX);
Serial.print(":");
Serial.print(mac[1], HEX);
Serial.print(":");
Serial.print(mac[2], HEX);
Serial.print(":");
Serial.print(mac[3], HEX);
Serial.print(":");
Serial.print(mac[4], HEX);
Serial.print(":");
Serial.println(mac[5], HEX);

server.onRequestBody( {

if (request->url() == "/spi") {
  printf("On request body data: %s\n", data);
  DynamicJsonBuffer jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject((const char*)data);
  if (root.success()) {
    if (root.containsKey("command")) {
      SPISlave.setData(root["command"].asString());


      digitalWrite(LPC_INT_PIN, 1);
    }
  }
  request->send(200, "text/plain", "end");
}

});
server.begin();

aClient = new AsyncClient();

aClient->onDisconnect( {
Serial.println("############ Async Client Disconnect ############");
c->free();
delete c;
});

aClient->onConnect( {
Serial.println("Async Client Connected");
}, NULL);

aClient->onData( {
Serial.print("\r\nData: ");
Serial.println(len);
uint8_t d = (uint8_t)data;
for (size_t i = 0; i < len; i++)
Serial.write(d[i]);
}, NULL);

if (!aClient->connect(BASE_HUE_URL, BASE_HUE_PORT)) {
Serial.println("Connect Fail\n");
AsyncClient * client = aClient;
aClient = NULL;
delete client;
}
}

void loop()
{
if ((WiFi.status() == WL_CONNECTED)) {

  aClient->write(PUT_HUE_URL);

}
'''

This message was deleted
Sorry for the mess. Above is a cut from my code. The thing i am trying to do is to send put messages to hue brigde all the time. How can i achieve this?