WDT reset cause 4 after reinstalling Arduino - c++
I try to control my LED strip with an Android app.
I reinstalled the Arduino IDE since I didn't like the Windows-store version. The serial monitor broke for whatever reason so I switched back to the Windows-store version.
But now I'm getting a WDT reset error, which I can't seem to overcome.
I'm also using Adafruit_NeoPixel and wherever I put "ledstrip.begin" or "ledstrip.show" seems to break it.
#include <ESP8266WiFi.h>
#include <Adafruit_NeoPixel.h>
byte RED = 14;
byte GREEN = 12;
byte BLUE = 13;
byte PIN_COUNT = 20;
Adafruit_NeoPixel ledstrip = Adafruit_NeoPixel(PIN_COUNT, 6, NEO_RGB + NEO_KHZ800); //(num of leds, )
WiFiServer server(port);
void setup()
{
Serial.begin(115200);
delay(10);
ledstrip.begin();
Serial.print("Connecting to: ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
byte tries;
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
tries++;
Serial.println(".");
if (tries == 5)
{
Serial.println("Connection failed");
return;
}
}
Serial.println("\nWiFi connected");
server.begin();
Serial.println("Server URL: ");
Serial.print(WiFi.localIP());
}
void print_tokens(char* strings)
{
byte index = sizeof(strings);
for (int n = 0; n < index; n++)
{
Serial.println(strings[n]);
}
}
char *tokenize_request(String request)
{
char requestArray[1024];
char *ptr = NULL;
byte index = 0;
char *strings[10];
strcpy(requestArray, request.c_str());
ptr = strtok(requestArray, ";");
while (ptr != NULL) {
strings[index] = ptr;
index++;
ptr = strtok(NULL, ";");
}
return *strings;
}
void loop()
{
WiFiClient responder = server.available();
if (!responder)
{
return;
}
while (!responder.available())
{
delay(1);
}
String request = responder.readStringUntil('#');
char *strings[10] = {tokenize_request(request)};
print_tokens(*strings);
int mode = atoi(strings[0]);
int R = atoi(strings[1]);
int G = atoi(strings[2]);
int B = atoi(strings[3]);
if (mode == 1)
{
ledstrip.setPixelColor(5, R, G, B);
}
if (mode == 0)
{
ledstrip.setPixelColor(5, 0, 0, 0);
}
ledstrip.show();
delay(1);
Serial.println("------------------------------------------------------------------");
}
Serial monitor output:
Related
3x Arduino + ESP32 with ESP-NOW
The configuration on "machine" looks like this: Computer with custom app WPF C#, have connected ESP32-sender. On other side of room there is ESP32 as recaiver that have connected to it 3 arduino due, that controls a lot of stepper motors. My problem is, that if I send a single command all works great. Directly on other side it executes. The problem starts when there is a lot of commands to send. ESP32 starts to makes Delivery fail status and after that moment all further commands are lost. That's the code of Master-ESP connected to PC. Which arduino to send is decide by one of the symbols on begin of message "!,#,#" #include <esp_now.h> #include <WiFi.h> #include <Wire.h> uint8_t broadcastAddress[] = {0x94, 0xB9, 0x7E, 0xD0, 0x93, 0x64}; String inMess; typedef struct Message { char a[100]; } Message; // Variable to store if sending data was successful String success; Message message; Message send_message; esp_now_peer_info_t peerInfo; char incoming; String full = ""; bool text_done = false; bool sended = false; // Callback when data is sent void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { //Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success*" : "Delivery Fail*"); if (status ==0){ success = "Delivery Success :)"; text_done = false; full = ""; sended = false; } else{ success = "Delivery Fail :("; delay(10); sended = false; Serial.println(success); } } // Callback when data is received void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { memcpy(&message, incomingData, sizeof(message)); Serial.println(message.a); } void setup() { // Init Serial Monitor Serial.begin(115200); // Set device as a Wi-Fi Station WiFi.mode(WIFI_STA); Serial.println(WiFi.macAddress()); // Init ESP-NOW if (esp_now_init() != ESP_OK) { Serial.println("Error initializing ESP-NOW"); return; } esp_now_register_send_cb(OnDataSent); // Register peer memcpy(peerInfo.peer_addr, broadcastAddress, 6); peerInfo.channel = 0; peerInfo.encrypt = false; // Add peer if (esp_now_add_peer(&peerInfo) != ESP_OK){ Serial.println("Failed to add peer"); return; } esp_now_register_recv_cb(OnDataRecv); } void loop() { if(Serial.available() > 0 && !text_done){ incoming = Serial.read(); if(incoming == '\n'){ text_done = true; full.trim(); full.toUpperCase(); } if(text_done == false){ full += incoming; } } if(text_done){ if(full[0] != '!' && full[0] != '#' && full[0] != '#'){ //check if text is worth sending to other esp text_done = false; full = ""; } } if(text_done){ if(!sended){ full.toCharArray(send_message.a,sizeof(send_message)); esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &send_message, sizeof(send_message)); if (result == ESP_OK) { //Serial.println("Sent success*"); sended = true; } else { Serial.println("Error sending*"); delay(10); } } } } That's the code of recaiver ESP #include <esp_now.h> #include <WiFi.h> #include <SoftwareSerial.h> #include <Wire.h> SoftwareSerial worker; SoftwareSerial tool; //Serial2 is Table, software serials are others uint8_t broadcastAddress[] = {0x7C, 0x9E, 0xBD, 0x4B, 0x47, 0xA4}; String outMess; String outMessTable; String outMessTool; String inMess; typedef struct Message { char a[100]; } Message; String success; Message message; Message send_message; bool sended = true; String again_message = ""; esp_now_peer_info_t peerInfo; void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) { //Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Delivery Success" : "Delivery Fail"); if (status == 0) { success = "Delivery Success :)"; sended = true; again_message = ""; } else { success = "Delivery Fail :("; sended = false; delay(5); } } void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) { memcpy(&message, incomingData, sizeof(message)); Serial.println(message.a); sendTo((String)message.a); } void setup() { // Init Serial Monitor Serial.begin(115200); Serial2.begin(115200, SERIAL_8N1, 16, 17); //rx tx worker.begin(57600, SWSERIAL_8N1, 25, 26, false); if (!worker) { Serial.println("Invalid SoftwareSerial pin configuration, check config"); while (1) { delay (1000); } } //rx tx tool.begin(57600, SWSERIAL_8N1, 32, 33, false); if (!tool) { Serial.println("Invalid SoftwareSerial pin configuration, check config"); while (1) { delay (1000); } } // Set device as a Wi-Fi Station WiFi.mode(WIFI_STA); Serial.println(WiFi.macAddress()); // Init ESP-NOW if (esp_now_init() != ESP_OK) { Serial.println("Error initializing ESP-NOW"); return; } // Once ESPNow is successfully Init, we will register for Send CB to // get the status of Trasnmitted packet esp_now_register_send_cb(OnDataSent); // Register peer memcpy(peerInfo.peer_addr, broadcastAddress, 6); peerInfo.channel = 0; peerInfo.encrypt = false; // Add peer if (esp_now_add_peer(&peerInfo) != ESP_OK) { Serial.println("Failed to add peer"); return; } // Register for a callback function that will be called when data is received esp_now_register_recv_cb(OnDataRecv); } void loop() { // Set values to send if(sended){ if (worker.available() > 0) {//! char t = worker.read(); if(t == '\n'){ outMess.trim(); sendToEsp(outMess,"!"); outMess = ""; } else{ outMess += t; } } }else{ if(again_message.length()>0){ delay(10); sendToEsp(again_message.substring(1),again_message.substring(0,1)); }else{ sended = true; } } if(sended){ if (tool.available() > 0) {//# char t = tool.read(); if(t == '\n'){ outMessTool.trim(); sendToEsp(outMessTool,"#"); outMessTool = ""; } else{ outMessTool += t; } } }else{ if(again_message.length()>0){ delay(10); sendToEsp(again_message.substring(1),again_message.substring(0,1)); }else{ sended = true; } } if(sended){ if (Serial2.available() > 0) { //# char t = Serial2.read(); if(t == '\n'){ outMessTable.trim(); sendToEsp(outMessTable,"#"); outMessTable = ""; }else{ outMessTable += t; } } }else{ if(again_message.length()>0){ delay(10); sendToEsp(again_message.substring(1),again_message.substring(0,1)); }else{ sended = true; } } if(Serial.available() > 0){ outMess = Serial.readStringUntil('\n'); //read command from pc outMess.trim(); // remove uneccesery spaces sendTo(outMess); } } void sendToEsp(String text, String which){ String mess = which + text; again_message = mess; mess.toCharArray(send_message.a,sizeof(send_message)); esp_err_t result = esp_now_send(broadcastAddress, (uint8_t *) &send_message, sizeof(send_message)); if (result == ESP_OK) { // Serial.println("Sent with success"); } else { Serial.println("Error sending the data"); sended = true; again_message = ""; } } void sendTo(String outMess){ Serial.print("="); Serial.print(outMess); if(outMess[0] == '!'){ //worker worker.enableTx(true); worker.println(outMess.substring(1)); worker.enableTx(false); Serial.println("send to worker"); } if(outMess[0] == '#') {//table Serial2.println(outMess.substring(1)); Serial.println("send to table"); } if(outMess[0] == '#'){ //tool tool.enableTx(true); tool.println(outMess.substring(1)); tool.enableTx(false); Serial.println("send to tool"); } } If I send one message with a delay of writing next one by hand it works great. If the message is sended via c# very fast, esp32 is handling first few of them then losing on sending or recaiving, sometimes both of esp32 sometimes only one. How could I prevent that to make stable connection ?
PubSubClient ESP32 disconnected while receive message
I create a project to receive message from MQTT. My full code is here https://github.com/kamshory/OTP-Mini/blob/main/Server/Server.ino WiFiClient espClient; PubSubClient client(espClient); void setup() { char * mqttServer = "192.168.1.3"; client.setServer(mqttServer, 1883); client.setCallback(mqttCallback); } void mqttCallback(const char* topic, byte* payload, unsigned int length) { Serial.print("Message arrived on topic: "); Serial.print(topic); Serial.print("Message: "); char * mqttTopic = "sms"; String messageTemp; for (int i = 0; i < length; i++) { Serial.print((char)payload[i]); messageTemp += (char)payload[i]; } Serial.println(); // Feel free to add more if statements to control more GPIOs with MQTT // If a message is received on the topic esp32/output, you check if the message is either "on" or "off". // Changes the output state according to the message if (String(topic) == String(mqttTopic)) { } } void mqttReconnect() { Serial.print("WiFi status = "); Serial.println(WiFi.status()); char * clientId = "php"; char * mqttUsername = "user"; char * mqttPassword = "pass"; char * mqttTopic = "sms"; // Loop until we're reconnected while (!client.connected()) { Serial.print("Attempting MQTT connection "); // Attempt to connect if (client.connect(clientId, mqttUsername, mqttPassword)) { Serial.println("connected"); // Subscribe boolean sub = client.subscribe("sms"); Serial.println(sub); } else { Serial.print("failed, rc="); Serial.print(client.state()); Serial.println(" try again in 5 seconds"); // Wait 5 seconds before retrying delay(5000); } } } When ESP32 publish a message in a topic, the message is received by subscriber (I create the subscriber with Java). But when it try to receive the message with callback, the client is disconnected. I try to debug with edit library on file PubSubClient.cpp boolean PubSubClient::loop() { if (connected()) { unsigned long t = millis(); if ((t - lastInActivity > MQTT_KEEPALIVE*1000UL) || (t - lastOutActivity > MQTT_KEEPALIVE*1000UL)) { if (pingOutstanding) { this->_state = MQTT_CONNECTION_TIMEOUT; _client->stop(); return false; } else { buffer[0] = MQTTPINGREQ; buffer[1] = 0; _client->write(buffer,2); lastOutActivity = t; lastInActivity = t; pingOutstanding = true; } } if (_client->available()) { uint8_t llen; uint16_t len = readPacket(&llen); uint16_t msgId = 0; uint8_t *payload; if (len > 0) { lastInActivity = t; uint8_t type = buffer[0]&0xF0; if (type == MQTTPUBLISH) { if (callback) { uint16_t tl = (buffer[llen+1]<<8)+buffer[llen+2]; /* topic length in bytes */ memmove(buffer+llen+2,buffer+llen+3,tl); /* move topic inside buffer 1 byte to front */ buffer[llen+2+tl] = 0; /* end the topic as a 'C' string with \x00 */ char *topic = (char*) buffer+llen+2; // msgId only present for QOS>0 if ((buffer[0]&0x06) == MQTTQOS1) { msgId = (buffer[llen+3+tl]<<8)+buffer[llen+3+tl+1]; payload = buffer+llen+3+tl+2; callback(topic,payload,len-llen-3-tl-2); buffer[0] = MQTTPUBACK; buffer[1] = 2; buffer[2] = (msgId >> 8); buffer[3] = (msgId & 0xFF); _client->write(buffer,4); lastOutActivity = t; } else { payload = buffer+llen+3+tl; callback(topic,payload,len-llen-3-tl); } } } else if (type == MQTTPINGREQ) { buffer[0] = MQTTPINGRESP; buffer[1] = 0; _client->write(buffer,2); } else if (type == MQTTPINGRESP) { pingOutstanding = false; } } else if (!connected()) { // readPacket has closed the connection return false; } } return true; } return false; } The type value is 208 which is MQTTPINGRESP not 48 which is MQTTPUBLISH. So, where is the problem? Is my library or my code? I download library from https://www.arduino.cc/reference/en/libraries/pubsubclient/
Arduino compiler failing with error code - invalid types 'int[int]' for array subscript
Quite a bit of untested code but the only thing really concerning me at the moment is my DISPLAY variable. I don't see how it is much different than my FONT array (which works fine) yet DISPLAY is the one that gets 'invalid types 'int[int]' for array subscript' I should be able to index an array of integers with integers (at least I have been with FONT). #include <WiFiNINA.h> #include <NTPClient.h> #include <WiFiUdp.h> #include "font.h" const int PIXEL_WIDTH = 30; const int PIXEL_HEIGHT = 5; int DISPLAY[PIXEL_HEIGHT][PIXEL_WIDTH] = {}; bool MILI_TIME = false; String FORMATTING[2] = {"LONGS","SHORTH:LONGM"}; char ssid[] = "REMOVED"; // your network SSID (name) between the " " char pass[] = "REMOVED"; // your network password between the " " int keyIndex = 0; // your network key Index number (needed only for WEP) int status = WL_IDLE_STATUS; // connection status WiFiServer server(80); // server socket WiFiClient client = server.available(); WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP); int ledPin = LED_BUILTIN; void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); while (!Serial); // dont do anything until there is a serial connection enable_WiFi(); connect_WiFi(); server.begin(); printWifiStatus(); timeClient.begin(); timeClient.setTimeOffset(-14400); } void loop() { timeClient.update(); client = server.available(); if (client) { printWEB(); } preRender(); } void preRender(){ String FILLED_FORMATTING[2] = FORMATTING; for(int i=0;i<2;i++){ FILLED_FORMATTING[i].replace("LONGH",leadWithZero(timeHours())); FILLED_FORMATTING[i].replace("LONGM",leadWithZero(timeMinutes())); FILLED_FORMATTING[i].replace("LONGS",leadWithZero(timeSeconds())); FILLED_FORMATTING[i].replace("SHORTH",timeHours()); FILLED_FORMATTING[i].replace("SHORTM",timeMinutes()); FILLED_FORMATTING[i].replace("SHORTS",timeSeconds()); } int x = 0; for(int i=0;i<FILLED_FORMATTING[0].length();i++){ int c_ID = charID(FILLED_FORMATTING[0][i]); if(c_ID < 38){ for(int j=0;j<5;j++){ DISPLAY[j][x] = FONT[c_ID][j][0]; x += 1; DISPLAY[j][x] = FONT[c_ID][j][1]; x += 1; DISPLAY[j][x] = FONT[c_ID][j][2]; x += 1; if(i != FILLED_FORMATTING[0].length()){ DISPLAY[j][x] = 0; x += 1; } } } } x = PIXEL_WIDTH-1; for(int i=FILLED_FORMATTING[1].length()-1;i>=0;i--){ int c_ID = charID(FILLED_FORMATTING[1][i]); if(c_ID < 38){ for(int j=0;j<5;j++){ DISPLAY[j][x] = FONT[c_ID][j][0]; x -= 1; DISPLAY[j][x] = FONT[c_ID][j][1]; x -= 1; DISPLAY[j][x] = FONT[c_ID][j][2]; x -= 1; if(i != 0){ DISPLAY[j][x] = 0; //<----------- compiler error here, and ofc all instances above x -= 1; } } } } } int charID(char c){ for(int i=0;i<FONT_ID.length();i++){ if(FONT_ID[i] == c){ return i; } } return 40; } String timeHours(){ if(MILI_TIME){ return String(timeClient.getHours()); } else{ return convFromMili(timeClient.getHours()); } } String timeMinutes(){ return String(timeClient.getMinutes()); } String timeSeconds(){ return String(timeClient.getSeconds()); } String leadWithZero(String t){ if(t.length() < 2){ t = "0"+t; return t; } } String convFromMili(int t){ if(t > 12){ t -= 12; }else if(t == 0){ t += 12; } String ts = String(t); return ts; } void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print your board's IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); // print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); Serial.print("To see this page in action, open a browser to http://"); Serial.println(ip); } void enable_WiFi() { // check for the WiFi module: if (WiFi.status() == WL_NO_MODULE) { Serial.println("Communication with WiFi module failed!"); // don't continue while (true); } String fv = WiFi.firmwareVersion(); if (fv < "1.0.0") { Serial.println("Please upgrade the firmware"); } } void connect_WiFi() { while (status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); status = WiFi.begin(ssid, pass); delay(10000); } } void printWEB() { if (client) { // if you get a client, Serial.println("new client"); // print a message out the serial port String currentLine = ""; // make a String to hold incoming data from the client while (client.connected()) { // loop while the client's connected if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // read a byte, then Serial.write(c); // print it out the serial monitor if (c == '\n') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: if (currentLine.length() == 0) { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println(); //create the buttons client.print(WiFi.getTime()); client.print("<br>"); client.print(timeClient.getEpochTime()); client.print("<br>"); client.print(timeClient.getFormattedTime()); client.print("<br>"); client.print(timeClient.getDay()); client.print("<br>"); client.print(timeClient.getHours()); client.print("<br>"); client.print(timeClient.getMinutes()); client.print("<br>"); client.print(timeClient.getSeconds()); client.print("<br>"); client.print("<div style=\"display:block;padding-left:calc(50% - 150px);margin-bottom:50px\"><div style=\"background-color:#e3e3e3;width:300px;height:120px;font-size:50px;text-align:center;padding-top:50px\">ON</div></div>"); client.print("<div style=\"display:block;padding-left:calc(50% - 150px)\"><div style=\"background-color:#e3e3e3;width:300px;height:120px;font-size:50px;text-align:center;padding-top:50px\">OFF</div></div>"); // The HTTP response ends with another blank line: client.println(); // break out of the while loop: break; } else { // if you got a newline, then clear currentLine: currentLine = ""; } } else if (c != '\r') { // if you got anything else but a carriage return character, currentLine += c; // add it to the end of the currentLine } if (currentLine.endsWith("GET /H")) { digitalWrite(ledPin, HIGH); } if (currentLine.endsWith("GET /L")) { digitalWrite(ledPin, LOW); } if (currentLine.endsWith("%VAL")) { // Trim 'GET /' and '%VAL' currentLine.remove(0,5); currentLine.remove(currentLine.indexOf("%"),4); Serial.println(currentLine); Serial.println(); } } } // close the connection: client.stop(); Serial.println("client disconnected"); } } font.h: int FONT[37][5][3] = {{{1,1,1},{1,0,1},{1,0,1},{1,0,1},{1,1,1},},{{1,1,0},{0,1,0},{0,1,0},{0,1,0},{1,1,1},},{{1,1,1},{0,0,1},{1,1,1},{1,0,0},{1,1,1},},{{1,1,1},{0,0,1},{1,1,1},{0,0,1},{1,1,1},},{{1,0,1},{1,0,1},{1,1,1},{0,0,1},{0,0,1},},{{1,1,1},{1,0,0},{1,1,1},{0,0,1},{1,1,1},},{{1,1,1},{1,0,0},{1,1,1},{1,0,1},{1,1,1},},{{1,1,1},{0,0,1},{0,0,1},{0,0,1},{0,0,1},},{{1,1,1},{1,0,1},{1,1,1},{1,0,1},{1,1,1},},{{1,1,1},{1,0,1},{1,1,1},{0,0,1},{1,1,1},},{{1,1,1},{1,0,1},{1,1,1},{1,0,1},{1,0,1},},{{1,1,0},{1,0,1},{1,1,0},{1,0,1},{1,1,0},},{{1,1,1},{1,0,0},{1,0,0},{1,0,0},{1,1,1},},{{1,1,0},{1,0,1},{1,0,1},{1,0,1},{1,1,0},},{{1,1,1},{1,0,0},{1,1,1},{1,0,0},{1,1,1},},{{1,1,1},{1,0,0},{1,1,1},{1,0,0},{1,0,0},},{{1,1,1},{1,0,0},{1,0,1},{1,0,1},{1,1,1},},{{1,0,1},{1,0,1},{1,1,1},{1,0,1},{1,0,1},},{{1,1,1},{0,1,0},{0,1,0},{0,1,0},{1,1,1},},{{0,0,1},{0,0,1},{0,0,1},{1,0,1},{1,1,1},},{{1,0,1},{1,0,1},{1,1,0},{1,0,1},{1,0,1},},{{1,0,0},{1,0,0},{1,0,0},{1,0,0},{1,1,1},},{{1,1,1},{1,1,1},{1,0,1},{1,0,1},{1,0,1},},{{1,1,0},{1,0,1},{1,0,1},{1,0,1},{1,0,1},},{{1,1,1},{1,0,1},{1,0,1},{1,0,1},{1,1,1},},{{1,1,1},{1,0,1},{1,1,1},{1,0,0},{1,0,0},},{{1,1,1},{1,0,1},{1,0,1},{1,1,0},{0,0,1},},{{1,1,1},{1,0,1},{1,1,0},{1,0,1},{1,0,1},},{{0,1,1},{1,0,0},{0,1,0},{0,0,1},{1,1,0},},{{1,1,1},{0,1,0},{0,1,0},{0,1,0},{0,1,0},},{{1,0,1},{1,0,1},{1,0,1},{1,0,1},{1,1,1},},{{1,0,1},{1,0,1},{1,0,1},{0,1,0},{0,1,0},},{{1,0,1},{1,0,1},{1,0,1},{1,1,1},{1,1,1},},{{1,0,1},{1,0,1},{0,1,0},{1,0,1},{1,0,1},},{{1,0,1},{1,0,1},{1,1,1},{0,0,1},{1,1,1},},{{1,1,1},{0,0,1},{0,1,0},{1,0,0},{1,1,1},},{{0,0,0},{0,1,0},{0,0,0},{0,1,0},{0,0,0}}}; String FONT_ID = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ:"; did check - int D[5][30]; void setup() { } void loop() { D[0][0] = 0; } and of course its fine, so I'm just wondering where I went wrong in the mess above? and yes there's a good bit of mess/debugging stuff
Simple solution... don't use DISPLAY as a variable it seems. Changing to DISPLAY_ fixed it, figured the variable was defined as a normal integer somewhere... just not in my code.
How display a static map on TFT in arduino
I'm working on a function to display static map on TFT display (I use ESP32.). The map link is as follows (a http link): http://osm-static-maps.herokuapp.com/?geojson=[{%22type%22:%22Point%22,%22coordinates%22:[32.37956,51.66127]}]&height=400&width=600&zoom=13&type=jpeg and my code is as follows: #define WIFI_SSID "<your SSID>" #define PASSWORD "<your password>" #define LINK "http://osm-static-maps.herokuapp.com/?geojson=[{%22type%22:%22Point%22,%22coordinates%22:[32.37956,51.66127]}]&height=400&width=600&zoom=13&type=jpeg" #include <TJpg_Decoder.h> #include <WiFi.h> #include <HTTPClient.h> #include <TFT_eSPI.h> TFT_eSPI tft = TFT_eSPI(); #define BUFSIZE 40000 uint8_t* jpgbuffer; unsigned long jp = 0; bool tft_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap) { if ( y >= tft.height() ) return 0; tft.pushImage(x, y, w, h, bitmap); return 1; } void setup() { jpgbuffer = (uint8_t *) malloc (BUFSIZE); Serial.begin(115200); tft.begin(); tft.setRotation(1); tft.fillScreen(TFT_BLACK); TJpgDec.setJpgScale(1); TJpgDec.setSwapBytes(true); TJpgDec.setCallback(tft_output); WiFi.begin(WIFI_SSID, PASSWORD); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(); uint32_t t = millis(); bool loaded_ok = downFile(LINK, jpgbuffer); t = millis() - t; if (loaded_ok) { Serial.print("Downloaded in "); Serial.print(t); Serial.println(" ms."); } t = millis(); TJpgDec.drawJpg(0, 0, jpgbuffer, jp); t = millis() - t; Serial.print("Decoding and rendering: "); Serial.print(t); Serial.println(" ms."); } void loop() { } bool downFile(String url, uint8_t* jpgbuffer) { Serial.println("Downloading file from " + url); if ((WiFi.status() == WL_CONNECTED)) { HTTPClient http; http.begin(url); int httpCode = http.GET(); if (httpCode > 0) { if (httpCode == HTTP_CODE_OK) { int total = http.getSize(); int len = total; uint8_t buff[128] = { 0 }; WiFiClient * stream = http.getStreamPtr(); while (http.connected() && (len > 0 || len == -1)) { size_t size = stream->available(); if (size) { int c = stream->readBytes(buff, ((size > sizeof(buff)) ? sizeof(buff) : size)); memcpy (jpgbuffer + jp, buff, c); jp = jp + c; if (len > 0) { len -= c; } } yield(); } Serial.println(); Serial.print("[HTTP] connection closed or file end.\n"); } } else { Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str()); } http.end(); } return 1; } Everything is OK when I use the link below, for example: #define LINK "http://dellascolto.com/lorenz.jpg" But when I use the link below, the Arduino hangs after uploading the code! #define LINK "http://osm-static-maps.herokuapp.com/?geojson=[{%22type%22:%22Point%22,%22coordinates%22:[32.37956,51.66127]}]&height=400&width=600&zoom=13&type=jpeg" Apparently, when JSON part is removed from the map link, the program runs correctly. How to solve the problem.
The image doesn't fit your buffer. It is 78886 bytes strong. You only allocate 40000 bytes. Postpone allocation until you know the size: total = http.getSize(); *jpgbuffer = malloc(total); Note that in order to do so you meed pass jpgbuffer as uint8_t **.
strcmp brakes Arduino sketch
For a school project, I'm using an Arduino Uno together with a Parallax RFID, a LCD screen and an esp8226-wifi module. I'm trying to compare the scanned tag with the tags in the database and send the name of the tag owner to a terminal in the Blynk app. Everything works just fine until I put in the function that compares the tags. If I do that, everything stops working, even the code in the setup() part. How can I fix this? I think the problem has somehing to do with the strcmp. /* Libraries that need to be manually installed: Blynk libraries: https://github.com/blynkkk/blynk-library/releases/download/v0.5.0/Blynk_Release_v0.5.0.zip LiquidCrystal_I2C library: https://cdn.instructables.com/ORIG/FVH/K8OQ/J8UH0B9U/FVHK8OQJ8UH0B9U.zip */ #define BLYNK_PRINT Serial #include <SoftwareSerial.h> #include <ESP8266_Lib.h> #include <BlynkSimpleShieldEsp8266.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> //Setting up the Blynk wifi connection #define ESP8266_BAUD 9600 char auth[] = "87b00838cd834e4e87a0422265cc7a9e"; char ssid[] = "bbox2-56b2"; char pass[] = "91C2D797F6"; //Setting up the virtual pins WidgetTerminal terminal(V1); BLYNK_WRITE(V1){} //Setting up the RFID #define RFIDEnablePin 8 #define RFIDSerialRate 2400 String RFIDTAG=""; //Holds the RFID Code read from a tag String DisplayTAG = ""; //Holds the last displayed RFID Tag //Setting up the LCD LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //Setting up the serial connection SoftwareSerial EspSerial(2, 3); ESP8266 wifi(&EspSerial); void setup() { //Serial communication Serial.begin(RFIDSerialRate); EspSerial.begin(ESP8266_BAUD); Serial.begin(RFIDSerialRate); delay(10); //Blynk setup Blynk.begin(auth, wifi, ssid, pass); //LCD setup lcd.begin(16,2);//16 kolommen, 2 rijen lcd.backlight(); //RFID setup pinMode(RFIDEnablePin,OUTPUT); digitalWrite(RFIDEnablePin, LOW); terminal.println("Terminal printing succesfull"); terminal.flush(); } void loop() { if(Serial.available() > 0) { ReadSerial(RFIDTAG); } if(DisplayTAG!=RFIDTAG) { DisplayTAG=RFIDTAG; // PROBLEM STARTS HERE //Tag database char tags[10][10] = {"6196", "6753", "5655", "69EC", "9FFC"}; char owners[10][30] = {"per1", "per2", "per3", "per4", "per5"}; int i = 0; int j = 0; int ownerLength = 0; char lastTag[10]; RFIDTAG.toCharArray(lastTag, 10); while (i < 10) { if (strcmp(tags[i], lastTag) == 0) { ownerLength = strlen(owners[i]); while (j < ownerLength) { terminal.print(owners[i][j]); } terminal.println("has entered the parking\n\r"); terminal.flush(); break; } i++; } i = 0; j = 0; //PROBLEM ENDS HERE lcd.clear(); lcd.setCursor(0,0); lcd.print("Last tag:"); lcd.setCursor(0,1); lcd.print(RFIDTAG); digitalWrite(RFIDEnablePin, HIGH); delay(1000); digitalWrite(RFIDEnablePin, LOW); } Blynk.run(); } //Function for reading the tag void ReadSerial(String &ReadTagString) { int bytesread = 0; int val = 0; char code[10]; String TagCode=""; if(Serial.available() > 0) { if((val = Serial.read()) == 10) { bytesread = 0; while(bytesread<10) // Reads the tag code { if( Serial.available() > 0) { val = Serial.read(); if((val == 10)||(val == 13)) // If header or stop bytes before the 10 digit reading { break; // Stop reading } code[bytesread] = val; // Add the digit bytesread++; // Ready to read next digit } } if(bytesread == 10) // If 10 digit read is complete { for(int x=6;x<10;x++) //Copy the Chars to a String { TagCode += code[x]; } ReadTagString = TagCode; //Returns the tag ID while(Serial.available() > 0) //Burn off any characters still in the buffer { Serial.read(); } } bytesread = 0; TagCode=""; } } }