Code Monkey home page Code Monkey logo

Comments (9)

maakbaas avatar maakbaas commented on August 23, 2024

Thanks you for reporting this issue. I have not experienced this myself yet. Can you post a minimal code example to see if I can reproduce this and investigate it further?

from esp8266-iot-framework.

lylasolar avatar lylasolar commented on August 23, 2024

Sorry for the late response. Here is my code below... Thanks, Maakbass.
Pls, a quick question --> how do I call the webServer when the program is running? I tried adding webServer.begin() to the setup, but vscode/platformio threw error(expected unqualified-id before '.' token). The only way I could gain access to the webServer automatically is to turn off my router and restart the esp8266.

// My code
#include <Arduino.h>
#include "WiFiManager.h"
#include "webServer.h"
#include "updater.h"
#include "fetch.h"
#include "configManager.h"
#include "timeSync.h"
#include <SoftwareSerial.h>
#include <ArduinoJson.h>
#include <PubSubClient.h>
#include <ESP8266httpUpdate.h>
#include "LittleFS.h"
int rxPin = D6;
int txPin = D5;

SoftwareSerial linkSerial(rxPin, txPin);

const char *API = "pls put your api to test";
//String bodyPayload = "{\"id\": 199087, \"name\": \"kelvin\", \"usage\":121.40, \"balance\":144.90}";

char JSONmessageBuffer[1000];
char jsonData[500];
const int blueLed = D4; // multitasking led
int ledOpState = LOW;   //publish data operation led

/*** Serial LED states for software data sent ***/
bool serialState = false;
unsigned long prevSerialTime = 0;
unsigned long prevSerialTime2 = 0;
unsigned long resetTimePrev = 0;

struct taskPost
{
  unsigned long ratePost;
  unsigned long previousPost;
};

/*struct taskGet
{
  unsigned long rateGet;
  unsigned long previousGet;
};*/

taskPost taskA = {.ratePost = 10000, .previousPost = 0};
//taskGet taskB = {.rateGet = 20000, .previousGet = 0};

void setup()
{
  // put your setup code here, to run once:
  delay(15000);
  Serial.begin(115200);
  while (!Serial)
    continue;
  linkSerial.begin(9600);
  //delay(1500);
  delay(1000);
  delay(1000);
  delay(2000);
  LittleFS.begin();
  GUI.begin();
  configManager.begin();
  WiFiManager.begin("ESP_AP");
  timeSync.begin();
  pinMode(blueLed, OUTPUT);
}

/******* Software Serial data transfer(uno-ESP8266) led blink function ****/
void serialData()
{
  if (millis() - prevSerialTime >= 60000)
  { //turn off delay (blue led) is 1 min
    digitalWrite(blueLed, HIGH);
    serialState = false;
    prevSerialTime = millis();
  }

  if (serialState == false)
  {
    if (millis() - prevSerialTime2 >= 3000)
    {
      digitalWrite(blueLed, LOW);
      prevSerialTime2 = millis();
    }
  }
}

void httpsPost()
{
  //task A
  if (taskA.previousPost == 0 || (millis() - taskA.previousPost > taskA.ratePost))
  {
    taskA.previousPost = millis();

    //do task
    //Serial.print("Free Heap: ");
    //Serial.println(ESP.getFreeHeap());

    fetch.begin(API);
    fetch.addHeader("Content-Type", "application/json");
    fetch.POST(JSONmessageBuffer);

    while (fetch.busy())
    {
      //serialData();
      if (fetch.available())
      {
        Serial.write(fetch.read());
      }
      else{
        Serial.println("(Error) -> The HTTPS response stopped working!!!");
      }
    }
    fetch.clean();
  }
}

/*void httpsGet()
{
  if (taskB.previousGet == 0 || millis() - taskB.previousGet > taskB.rateGet)
  {
    taskB.previousGet = millis();

    fetch.GET("https://lylasolutions.000webhostapp.com/db.json");

    //Serial.print(fetch.readString());
    String json = fetch.readString();
    const size_t capacity = JSON_OBJECT_SIZE(4) + 70;
    DynamicJsonDocument doc(capacity);
    DeserializationError error = deserializeJson(doc, json);
    if (error)
    {
      Serial.print(F("deserializeJson() failed: "));
      Serial.println(error.c_str());
    }

    long meter_id = doc["meter_id"];        
    const char *customer_name = doc["customer_name"];
    float power_usage = doc["power_usage"];      
    float power_balance = doc["power_balance"];     

    Serial.print("meter_id: ");
    Serial.println(meter_id);

    Serial.print("customer_name: ");
    Serial.println(customer_name);

    Serial.print("power_usage: ");
    Serial.println(power_usage);

    Serial.print("power_balance: ");
    Serial.println(power_balance);

    Serial.println("");
    fetch.clean();
  }
}*/

void loop()
{
  // put your main code here, to run repeatedly:
  //software interrupts
  WiFiManager.loop();
  updater.loop();
  httpsPost();

  /*** ArduinoJSON v6 was used to collect JsonData from software serial*/
  if (linkSerial.available())
  {
    const size_t capacity = JSON_OBJECT_SIZE(23) + 310;
    DynamicJsonDocument doc(capacity);
    deserializeJson(doc, linkSerial);
    /*DeserializationError error = deserializeJson(doc, linkSerial);
    if (error)
    {
      Serial.print(F("deserializeJson() failed: "));
      Serial.println(error.c_str());
    }*/

    serializeJson(doc, JSONmessageBuffer);
    //Serial.println(JSONmessageBuffer);

    //snprintf(jsonData, sizeof(jsonData), JSONmessageBuffer);
    //Serial.print("Publish message: ");
    //Serial.println(jsonData);
  }

  //httpsGet();
}

from esp8266-iot-framework.

lylasolar avatar lylasolar commented on August 23, 2024

from esp8266-iot-framework.

maakbaas avatar maakbaas commented on August 23, 2024

I have tried your sketch, and filled in for the API url 'https://api.github.com'. I have not observed any resets or freezes, so I am not sure how I can support.

What kind of response are you getting from your API? Is this a small or a large payload?

from esp8266-iot-framework.

lylasolar avatar lylasolar commented on August 23, 2024

from esp8266-iot-framework.

maakbaas avatar maakbaas commented on August 23, 2024

In your example sketch you have basically no loop time in between HTTPS requests. Are you sure this is what you want to do, and that this is ok for the server? You are sending the request basically every second/few seconds. I can imagine that the server starts blocking this at one point?

I will try with your API call as well

from esp8266-iot-framework.

lylasolar avatar lylasolar commented on August 23, 2024

from esp8266-iot-framework.

maakbaas avatar maakbaas commented on August 23, 2024

Hi lylasolar,

I can't run your complete program. If I build the program I get a lot of resets, but these resets stop when I comment the SoftwareSerial functionality. Maybe this causes resets since I do not have the hardware setup that you have?

When I comment this part the https requests run fine, even though I can't POST the right payload to the server. I have not encountered any resets or hangs still.

Since I can not really reproduce the issue, I also can not really understand whats going on or help out further. Right now it also seems that the issue is not with the fetch class itself, and therefore I will close this issue for now.

I am very sorry that I can't be of more help. If you figure out what is going on, I am always interested to learn about it. Also if you find a more specific repeatable issue with one of the functions of the framework, feel free to open a new issue :).

from esp8266-iot-framework.

lylasolar avatar lylasolar commented on August 23, 2024

from esp8266-iot-framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.