Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <AsyncTCP.h>
- #include <ESPAsyncWebServer.h>
- const char *ssid = "";
- const char *password = "";
- int counter_wifi = 0;
- AsyncWebServer server(80);
- const uint16_t SAMPLESPERSEND = 512;
- const uint8_t SAMPLESSEND = 16; // 512*16 = 8196
- const uint8_t SAMPLESNUMSIZE = 8; // as your nums are 0.271184 so 8 chars
- float myMeasureVals [SAMPLESPERSEND * SAMPLESSEND];
- char myValueArray[SAMPLESPERSEND * (SAMPLESNUMSIZE + 1) + 2 + 1] = {'\0'};
- char numBufferArray[SAMPLESNUMSIZE + 1] = {'\0'}; // Converter helper array
- void setup() {
- Serial.begin(500000);
- Serial.println();
- Serial.println();
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print(".");
- counter_wifi++;
- if (counter_wifi >= 10) { //after 5 seconds timeout - reset board (on unsucessful connection)
- ESP.restart();
- }
- }
- Serial.println("WiFi connected.");
- Serial.println("IP Address: ");
- Serial.println(WiFi.localIP());
- server.on("/array", HTTP_GET, [](AsyncWebServerRequest * request) {
- for (uint8_t j = 0; j < SAMPLESSEND; j++) {
- if (j == 0) strcat (myValueArray, "[");
- for (uint16_t i = 0; i < SAMPLESPERSEND; i++) {
- // float myTempValue = function2GetValues(); // direct froma function
- float myTempValue = myMeasureVals [i * j];
- // dtostrf(floatvar, StringLengthIncDecimalPoint, numVarsAfterDecimal, charbuf);
- dtostrf(myTempValue, 2, 6, numBufferArray);
- strcat (myValueArray, numBufferArray);
- strcat (myValueArray, ",");
- }
- if (j == SAMPLESSEND - 1) myValueArray [strlen(myValueArray) - 1] = ']'; // overwrite the last ',' with ']'
- Serial.println(myValueArray);
- request->send(myValueArray);
- myValueArray[0] = '\0'; // empty array for next part
- }
- });
- DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
- server.begin();
- }
- void loop() {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement