Hi!
Currently i'm working on a project with a 32 x 8 MAX7219 led matrix and a Wemos D1 Mini Lite that fetches text from a server via the http protocol, which is then shown on the matrix. This seemed quite easy. However, I'm stuck
. When I execute the code, everything looks fine. But the problem is that after around an hour of operation (not really consistent though, max 3 hours), the text is not refreshed, making the current text display infinitely.
By checking the access logs on my server, it became clear that the Wemos doesn't make any http calls to my server anymore in that 'failing stage'. The WiFi that the Wemos operates on is quite stable.
The code can be found below.
Thanks,
Jakob
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <FC16.h>
const char* ssid = "----------";
const char* password = "----------";
char payloadChar[255];
String payload = "";
int lasthttpCode = 0;
int payloadLength = 0;
const int csPin = D4; // CS pin used to connect FC16
const int displayCount = 4; // Number of displays
const int scrollDelay = 30; // Scrolling speed - pause in ms
int Short = 0;
int Counter = 0;
FC16 display = FC16(csPin, displayCount);
void setup() {
Serial.begin(9600);
WiFi.begin(ssid, password); // Connect to WiFi
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
display.begin(); // turn on display
display.setIntensity(1); // set brightness
display.clearDisplay(); // turn all LED off
display.setText("Connected to ---------.");
WiFi.softAPdisconnect (true); // Turn of AP
}
void loop() {
if(display.update()){ //If the current message has been shown; fetch new line
payload = "";
String fetchedText = fetchNewText();
payloadLength = fetchedText.length() + 1;
fetchedText.toCharArray(payloadChar, payloadLength); //setText doesn't take in strings
Serial.println(fetchedText);
display.setText(payloadChar);
}
}
String fetchNewText(){
HTTPClient http; //Declare an object of class HTTPClient
http.begin("http://xxx.xxx.xxx.xxx/WEMOSMATRIX.php"); //Specify request destination
lasthttpCode = http.GET(); //Send the request
payload = http.getString(); //Get the request response payload
if(payload.length() < 15){
Short = 1;
payload = "";
}
else{
Short = 0;
}
http.end(); //Close connection
if(lasthttpCode > 0){
return payload;
}
else{
return "Error fetching the data";
}
}