openUC2 / UC2-Software-GIT

This repository hosts all necessary software for the UC2 project.
https://useetoo.org
Other
13 stars 6 forks source link

esp reboot crazy when ESP32_ledarr flashed #20

Closed BackMountainDevil closed 3 years ago

BackMountainDevil commented 3 years ago

Hello, amzing gentlemen and ladies. I am a student who want to learn yout project - APP_Incubator_Microscope. The 3D printing is done. I met a problem in the software [ESP32_ledarr ]().

I have flash the ESP32_motor_fluo the esp32 and test well with ras pi 4. But it occurred some problem when flash ESP32_ledarr . It could be flash into esp32. However, it went wired when it run.. When it connected to my wifi, it should tried to connect the mqtt server on ras pi. But in fact, it just reboot and connect my wifi. Then rebbot again..

Output in arduino serial

click to show code ```cpp // ----------- ----------- ----------- ----------- ----------- ----------- // ESP32 script to accept MQTT commands for UC2-control // by: Rene Lachmann // date: 11.09.2019 // based on Arduino-Interface by Rene Lachmann, Xavier Uwurukundu // fixes: // > 20.01.2020 Ientercept based correcd display updating -> Thomas Combriat (Oslo) //----------- ----------- ----------- ----------- ----------- ----------- // ---------------------------------------------------------------------------------------------------------------- // INCLUDES #include #include #include #include #include "Adafruit_GFX.h" #include "Adafruit_NeoMatrix.h" #include "Adafruit_NeoPixel.h" #include "SPI.h" #include // ---------------------------------------------------------------------------------------------------------------- // Global Defines #define MAX_CMD 3 #define MAX_INST 10 #define NCOMMANDS 15 #define MAX_MSG_LEN 40 #define LED_BUILTIN 26 #define LEDARR_PIN 23 //22 // ---------------------------------------------------------------------------------------------------------------- // Parameters // saved in strings, so that later (if implemented) e.g. easily changeable via Bluetooth -> to avoid connection errors std::string SETUP = "S007"; std::string COMPONENT = "LAR01"; std::string DEVICE = "ESP32"; std::string DEVICENAME; std::string CLIENTNAME; std::string SETUP_INFO; // ~~~~ Wifi ~~~~ const char *ssid = "Kearney"; const char *password = "asdcxz321.."; WiFiClient espClient; PubSubClient client(espClient); // ~~~~ MQTT ~~~~ const char *MQTT_SERVER = "172.20.10.5"; const char *MQTT_CLIENTID; const char *MQTT_USER; const char *MQTT_PASS = "23SPE"; const int MQTT_SUBS_QOS = 0; //const int MAX_CONN = 10; // maximum tries to connect const unsigned long period = 80000; // 80s unsigned long time_now = 0; // topics to listen to std::string stopicREC = "/" + SETUP + "/" + COMPONENT + "/RECM"; std::string stopicSTATUS = "/" + SETUP + "/" + COMPONENT + "/STAT"; std::string stopicANNOUNCE = "/" + SETUP + "/" + COMPONENT + "/ANNO"; // Deliminators for CMDs (published via payload-string) const char *delim_inst = "+"; const int delim_len = 1; // ~~~~ LED ~~~~ Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, LEDARR_PIN, NEO_MATRIX_TOP + NEO_MATRIX_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE, NEO_GRB + NEO_KHZ800); const int nrows = 8; const int ncols = 8; const int npixels = ncols * nrows; int ledNA = 4; struct RGB { byte r; byte g; byte b; }; struct RGB rgb; const int nPattern = 3; int activePattern = 0; bool light_pattern_bool[ncols][nrows][nPattern]; unsigned char light_pattern_color[ncols][nrows][nPattern][3]; // ~~~~ Commands ~~~~ const char *CMD; //Commands like: PXL -> limited to size of 3? int *INST[MAX_INST]; //Maximum number of possible instructions = std::vector INSTS; std::string CMDS; const char *COMMANDSET[NCOMMANDS] = {"NA", "PXL", "HLINE", "VLINE", "RECT", "CIRC", "LEFT", "RIGHT", "TOP", "BOTTOM", "CLEAR", "PRESET", "SETPRE", "FLYBY", "ALIVE"}; const char *INSTRUCTS[NCOMMANDS] = {"1", "4", "4", "4", "8", "6", "3", "3", "3", "3", "0", "1", "1", "1", "1"}; // ---------------------------------------------------------------------------------------------------------------- // Additional Functions void uc2wait(int period) { unsigned long time_now = millis(); while (millis() < time_now + period) { //wait approx. [period] ms }; } void matrix_show() { portDISABLE_INTERRUPTS(); // transmission to array should no be interrupted matrix.show(); matrix.show(); // to remove glitchy green corner portENABLE_INTERRUPTS(); // restore back interrupts } void setup_device_properties() { //std::time_t result = std::time(nullptr); //srand(result); // init randomizer with pseudo-random seed on boot //int randnum = rand() % 10000; int rand_number = random(1, 100000); std::stringstream srn; srn << rand_number; DEVICENAME = DEVICE + "_" + srn.str(); // random number generated up to macro MAX_RAND CLIENTNAME = SETUP + "_" + COMPONENT + "_" + DEVICENAME; SETUP_INFO = "This is:" + DEVICENAME + " on /" + SETUP + "/" + COMPONENT + "."; MQTT_CLIENTID = DEVICENAME.c_str(); //"S1_MOT2_ESP32" //Serial.print("MQTT_CLIENTID=");Serial.println(MQTT_CLIENTID); MQTT_USER = DEVICE.c_str(); Serial.println(SETUP_INFO.c_str()); } void setup_wifi() { uc2wait(10); // We start by connecting to a WiFi network Serial.println(); Serial.print("Device-MAC: "); Serial.println(WiFi.macAddress()); Serial.print("Connecting to "); Serial.print(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { uc2wait(500); Serial.print("."); } Serial.println(""); Serial.print("WiFi connected with IP:"); Serial.println(WiFi.localIP()); } int separateMessage(byte *message, unsigned int length) { //Serial.println("Seperating Message."); //Serial.print("Message="); char messageSep[length]; for (int myc = 0; myc < length; myc++) { messageSep[myc] = (char)message[myc]; //Serial.print(messageSep[myc]); } messageSep[length] = NULL; //Serial.println(""); Serial.print("Mess="); std::string mess(messageSep); Serial.println(mess.c_str()); size_t pos = 0; int i = 0; bool found_cmd = false; while ((pos = mess.find(delim_inst)) != std::string::npos) { if (!found_cmd) { //Serial.print("CMD-del@"); //Serial.println(pos); CMDS = mess.substr(0, pos); //Serial.print("CMDS="); CMD = CMDS.c_str(); //Serial.println(CMD); found_cmd = true; } else { INSTS.push_back(atoi(mess.substr(0, pos).c_str())); /* Serial.print("INST["); Serial.print(i); Serial.print("]="); Serial.println(INSTS[i]);*/ i++; } mess.erase(0, pos + delim_len); } if (!found_cmd) { //Serial.print("CMD-del@"); //Serial.println(pos); CMDS = mess.substr(0, pos); //Serial.print("CMDS="); CMD = CMDS.c_str(); //Serial.println(CMD); found_cmd = true; } else if (mess.length() > 0) { INSTS.push_back(atoi(mess.substr(0, pos).c_str())); /* Serial.print("INST["); Serial.print(i); Serial.print("]="); Serial.println(INSTS[i]);*/ i++; } else { Serial.println("Nothing found..."); } return i; mess.clear(); } bool isActivePixel() { return ((rgb.r + rgb.g + rgb.b) != 0); } void switchCurrentPreset(int num) { activePattern = num >= nPattern ? (nPattern - 1) : num; if (activePattern < 0) activePattern = 0; } void clearPattern() { //int xpos = 0; //int ypos = 0; Serial.println("ClearPAT."); matrix.fillScreen(0); matrix_show(); //if (!doNotDisturb) //{ for (int xpos = 0; xpos < ncols; xpos++) { for (int ypos = 0; ypos < nrows; ypos++) { light_pattern_color[xpos][ypos][activePattern][0] = 0; light_pattern_color[xpos][ypos][activePattern][1] = 0; light_pattern_color[xpos][ypos][activePattern][2] = 0; } } Serial.println("ClearPAT done."); //} } void reloadPresetPattern() { //int xpos = 0; //int ypos = 0; matrix.fillScreen(0); matrix_show(); for (int xpos = 0; xpos < ncols; xpos++) { for (int ypos = 0; ypos < nrows; ypos++) { if (light_pattern_bool[xpos][ypos][activePattern]) { rgb.r = (uint8_t)light_pattern_color[xpos][ypos][activePattern][0]; rgb.g = (uint8_t)light_pattern_color[xpos][ypos][activePattern][1]; rgb.b = (uint8_t)light_pattern_color[xpos][ypos][activePattern][2]; matrix.drawPixel(xpos, ypos, matrix.Color(rgb.r, rgb.g, rgb.b)); } else { //if (!doNotDisturb) //{ light_pattern_color[xpos][ypos][activePattern][0] = 0; light_pattern_color[xpos][ypos][activePattern][1] = 0; light_pattern_color[xpos][ypos][activePattern][2] = 0; //} } } } matrix_show(); } void drawRect(int x, int y, int w, int h, bool fill) { int offset_x = (ncols - ledNA * 2) * 0.5; int offset_y = (nrows - ledNA * 2) * 0.5; if (x < offset_x) x = offset_x; if (y < offset_y) y = offset_y; if (x > ncols - offset_x) x = ncols - offset_x; if (y > nrows - offset_y) y = nrows - offset_y; if ((x + w) > (ncols - offset_y)) w = ncols - offset_y - x; if ((y + h) > (nrows - offset_x)) h = nrows - offset_x - y; Serial.print("Corrected val for Rect = "); Serial.print(x); Serial.print(","); Serial.print(y); Serial.print(","); Serial.print(w); Serial.print(","); Serial.print(h); Serial.print(","); Serial.print(rgb.r); Serial.print(","); Serial.print(rgb.g); Serial.print(","); Serial.print(rgb.b); Serial.println("."); if (fill) matrix.fillRect(x, y, w, h, matrix.Color(rgb.r, rgb.g, rgb.b)); else matrix.drawRect(x, y, w, h, matrix.Color(rgb.r, rgb.g, rgb.b)); matrix_show(); } void setRGB(int r, int g, int b) { rgb.r = r; rgb.g = g; rgb.b = b; } void setNA(int select) { //if (select<5 & select> 0) //// MOD if (select < 5 && select > 0) { ledNA = select; Serial.print("NA set to: "); Serial.print(ledNA); Serial.println("."); setRGB(255, 255, 255); Serial.println("Call drawRect with: [0,0,8,8,255,255,255]. "); drawRect(0, 0, 8, 8, true); matrix_show(); } else { select = 0; ledNA = select; matrix.fillScreen(0); } } void updateColor(uint8_t r, uint8_t g, uint8_t b) { rgb.r = r; rgb.g = g; rgb.b = b; } void callback(char *topic, byte *message, unsigned int length) { //Serial.println("Callback-func called."); // test topics if (std::string(topic) == stopicREC) { //Serial.println(stopicREC.c_str()); int nINST = separateMessage(message, length); if (strcmp(CMD, COMMANDSET[0]) == 0) { setNA(INSTS[0]); } else if (strcmp(CMD, COMMANDSET[1]) == 0) { Serial.print("PXL working. :) -> nINST="); Serial.println(nINST); int xpos = INSTS[0] % ncols; int ypos = INSTS[0] / ncols; updateColor(INSTS[nINST - 3], INSTS[nINST - 2], INSTS[nINST - 1]); matrix.drawPixel(xpos, ypos, matrix.Color(rgb.r, rgb.g, rgb.b)); matrix_show(); //if (!doNotDisturb) //{ light_pattern_bool[xpos][ypos][activePattern] = true; light_pattern_color[xpos][ypos][activePattern][0] = INSTS[nINST - 3]; light_pattern_color[xpos][ypos][activePattern][1] = INSTS[nINST - 2]; light_pattern_color[xpos][ypos][activePattern][2] = INSTS[nINST - 1]; //} } else if (strcmp(CMD, COMMANDSET[4]) == 0) { //updateColor(INSTS[nINST - 4], INSTS[nINST - 3], INSTS[nINST - 2]); updateColor(INSTS[nINST - 3], INSTS[nINST - 2], INSTS[nINST - 1]); bool fill = !(INSTS[nINST - 1] == 1); drawRect(INSTS[0], INSTS[1], INSTS[2], INSTS[3], fill); } else if (strcmp(CMD, COMMANDSET[5]) == 0) { updateColor(INSTS[nINST - 3], INSTS[nINST - 2], INSTS[nINST - 1]); drawRect(INSTS[0], INSTS[1], INSTS[2], INSTS[3], true); } else if (strcmp(CMD, COMMANDSET[6]) == 0) { updateColor(INSTS[nINST - 3], INSTS[nINST - 2], INSTS[nINST - 1]); drawRect(0, 0, 4, 8, true); } else if (strcmp(CMD, COMMANDSET[7]) == 0) { updateColor(INSTS[nINST - 3], INSTS[nINST - 2], INSTS[nINST - 1]); drawRect(4, 0, 4, 8, true); } else if (strcmp(CMD, COMMANDSET[8]) == 0) { updateColor(INSTS[nINST - 3], INSTS[nINST - 2], INSTS[nINST - 1]); drawRect(0, 0, 8, 4, true); } else if (strcmp(CMD, COMMANDSET[9]) == 0) { updateColor(INSTS[nINST - 3], INSTS[nINST - 2], INSTS[nINST - 1]); drawRect(0, 4, 8, 4, true); } else if (strcmp(CMD, COMMANDSET[10]) == 0) { clearPattern(); } else if (strcmp(CMD, COMMANDSET[11]) == 0) { switchCurrentPreset(INSTS[0]); reloadPresetPattern(); } else if (strcmp(CMD, COMMANDSET[12]) == 0) { switchCurrentPreset(INSTS[0]); } else if (strcmp(CMD, COMMANDSET[13]) == 0) { //doNotDisturb = (INSTS[0] == 1); Serial.println("-DoNotDisturb- invoked. Not implemented."); } else if (strcmp(CMD, COMMANDSET[14]) == 0) { Serial.print("alive!"); } else { Serial.print("CMD not found."); } } else if (std::string(topic) == stopicSTATUS) { Serial.println(stopicSTATUS.c_str()); } else if (std::string(topic) == stopicANNOUNCE) { Serial.println(stopicANNOUNCE.c_str()); } else { Serial.print("Assortion Error: Nothing found for topic="); Serial.println(topic); } INSTS.clear(); } void reconnect() { // Loop until we're reconnected while (!client.connected()) { Serial.print("MQTT_CLIENTID="); Serial.println(MQTT_CLIENTID); Serial.print("topicSTATUS="); Serial.println(stopicSTATUS.c_str()); Serial.print("Attempting MQTT connection..."); // Attempt to connect if (client.connect(MQTT_CLIENTID, stopicSTATUS.c_str(), 2, 1, "0")) { // client.connect(MQTT_CLIENTID,MQTT_USER,MQTT_PASS,"esp32/on",2,1,"off") Serial.println("connected"); // Subscribe client.subscribe(stopicREC.c_str()); client.publish(stopicSTATUS.c_str(), "1"); client.publish(stopicANNOUNCE.c_str(), SETUP_INFO.c_str()); } else { Serial.print("failed, rc="); Serial.print(client.state()); Serial.println(" try again in 5 seconds"); // Wait 5 seconds before retrying uc2wait(5000); } } } // ---------------------------------------------------------------------------------------------------------------- // SETUP void setup() { Serial.begin(115200); // check for connected motors //status = bme.begin(); setup_device_properties(); Serial.print("VOID SETUP -> topicSTATUS="); Serial.println(stopicSTATUS.c_str()); setup_wifi(); client.setServer(MQTT_SERVER, 1883); client.setCallback(callback); pinMode(LED_BUILTIN, OUTPUT); time_now = millis(); //testCPP(); uc2wait(100); matrix.begin(); matrix.setBrightness(40); matrix.setTextWrap(false); matrix.fillScreen(0); //matrix.setCursor(x, 0); matrix.setTextColor(matrix.Color(40, 127, 200)); matrix.print(F("UC2")); matrix_show(); uc2wait(1000); matrix.fillScreen(0); matrix_show(); uc2wait(100); } // ---------------------------------------------------------------------------------------------------------------- // LOOP void loop() { if (!client.connected()) { reconnect(); } client.loop(); if (time_now + period < millis()) { client.publish(stopicSTATUS.c_str(), "1"); time_now = millis(); } } // ---------------------------------------------------------------------------------------------------------------- ```
click to show output [source code](https://github.com/openUC2/UC2-Software-GIT/blob/V2.0.0/HARDWARE_CONTROL/ESP32/GENERAL/ESP32_ledarr/src/ESP32_ledarr/ESP32_ledarr.ino). The latest version in master branch is the same result. ``` This is:ESP32_40863 on /S007/LAR01. VOID SETUP -> topicSTATUS=/S007/LAR01/STAT Device-MAC: 7C:9E:BD:06:F6:C8 Connecting to Kearney. WiFi connected with IP:172.20.10.6 abort() was called at PC 0x40085d61 on core 1 ELF file SHA256: 0000000000000000 Backtrace: 0x40088a8c:0x3ffb1e00 0x40088d09:0x3ffb1e20 0x40085d61:0x3ffb1e40 0x40085e8d:0x3ffb1e70 0x400d8a77:0x3ffb1e90 0x400d485e:0x3ffb1ec0 0x400d4a7c:0x3ffb1f20 0x400d116c:0x3ffb1f40 0x400d1b94:0x3ffb1f60 0x400d58ce:0x3ffb1fb0 0x4008a7be:0x3ffb1fd0 Rebooting... ets Jun 8 2016 00:22:57 rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff0018,len:4 load:0x3fff001c,len:1044 load:0x40078000,len:10124 load:0x40080400,len:5856 entry 0x400806a8 This is:ESP32_94258 on /S007/LAR01. VOID SETUP -> topicSTATUS=/S007/LAR01/STAT Device-MAC: 7C:9E:BD:06:F6:C8 Connecting to Kearney.. WiFi connected with IP:172.20.10.6 abort() was called at PC 0x40085d61 on core 1 ELF file SHA256: 0000000000000000 Backtrace: 0x40088a8c:0x3ffb1e00 0x40088d09:0x3ffb1e20 0x40085d61:0x3ffb1e40 0x40085e8d:0x3ffb1e70 0x400d8a77:0x3ffb1e90 0x400d485e:0x3ffb1ec0 0x400d4a7c:0x3ffb1f20 0x400d116c:0x3ffb1f40 0x400d1b94:0x3ffb1f60 0x400d58ce:0x3ffb1fb0 0x4008a7be:0x3ffb1fd0 Rebooting... ets Jun 8 2016 00:22:57 rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff0018,len:4 load:0x3fff001c,len:1044 load:0x40078000,len:10124 load:0x40080400,len:5856 entry 0x400806a8 This is:ESP32_40149 on /S007/LAR01. VOID SETUP -> topicSTATUS=/S007/LAR01/STAT Device-MAC: 7C:9E:BD:06:F6:C8 Connecting to Kearney.. WiFi connected with IP:172.20.10.6 abort() was called at PC 0x40085d61 on core 1 ```

Other normal software

Blink

Arduino - File - example - Basic - Blink. It will blink normal.

ws2812

click to show ```cpp // https://arduino.nxez.com/2019/06/10/arduino-driving-ws2812-led.html #include #ifdef __AVR__ #include // Required for 16 MHz Adafruit Trinket #endif // 控制 WS2812 灯条的引脚编号 #define PIN 26 //定义控制的 LED 数量 #define NUMPIXELS 5 Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); //相邻 LED 之间的延迟,单位毫秒 #define DELAYVAL 500 void setup() { #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000) clock_prescale_set(clock_div_1); #endif pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) Serial.begin(115200); Serial.println("start"); } void loop() { pixels.clear(); // Set all pixel colors to 'off' for(int i=0; i

serial output

the five led turn light one by one

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371 
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5856
entry 0x400806a8
start

ESP32_motor_fluo

click to show code ```cpp // ----------- ----------- ----------- ----------- ----------- ----------- // ESP32 script to accept MQTT commands for UC2-control // by: Rene Lachmann // date: 11.09.2019 // based on Arduino-Interface by Rene Lachmann, Xavier Uwurukundu //----------- ----------- ----------- ----------- ----------- ----------- // ---------------------------------------------------------------------------------------------------------------- // INCLUDES #include #include #include #include #include #include "driver/ledc.h" #include #include // ---------------------------------------------------------------------------------------------------------------- // Global Defines #define MAX_CMD 3 #define MAX_INST 10 #define NCOMMANDS 15 #define MAX_MSG_LEN 40 #define LED_BUILTIN 11 #define LED_FLUO_PIN 26 // ---------------------------------------------------------------------------------------------------------------- // Parameters // ~~~~ Device ~~~~ // create Pseudo-random number with temporal dependent input // saved in strings, so that later (if implemented) e.g. easily changeable via Bluetooth -> to avoid connection errors std::string SETUP = "S013"; //S006->Aurelie; S004->Barbora std::string COMPONENT = "MOT01"; // LAR01 //LED01 // MOT02=x,y // MOT01=z std::string DEVICE = "ESP32"; std::string DEVICENAME; std::string CLIENTNAME; std::string SETUP_INFO; // ~~~~ Wifi ~~~~ const char *ssid = "Kearney"; const char *password = "asdcxz321.."; WiFiClient espClient; PubSubClient client(espClient); // ~~~~ MQTT ~~~~ const char *MQTT_SERVER = "172.20.10.5"; const int MQTT_PORT = 1883; const char *MQTT_CLIENTID; const char *MQTT_USER; const char *MQTT_PASS = "23SPE"; const int MQTT_SUBS_QOS = 0; //const int MAX_CONN = 10; // maximum tries to connect const unsigned long period = 80000; // 80s unsigned long time_now = 0; // topics to listen to std::string stopicREC = "/" + SETUP + "/" + COMPONENT + "/RECM"; std::string stopicSTATUS = "/" + SETUP + "/" + COMPONENT + "/STAT"; std::string stopicANNOUNCE = "/" + SETUP + "/" + COMPONENT + "/ANNO"; // Deliminators for CMDs (published via payload-string) const char *delim_inst = "+"; const int delim_len = 1; // ~~~~ MOTOR ~~~~ StepMotor stepperZ = StepMotor(25,26,27,14); //normally: 25, 26, 27, 14 // 12, 14, 27, 26 StepMotor stepperY = StepMotor(5, 17, 16, 4); StepMotor stepperX = StepMotor(33, 32, 27, 14); // 27, 25, 32, 4 never connected to same ESP32 as stepperZ -> hence: universally possible // ~~~~ FLUO ~~~~ int led_fluo_pwm_frequency = 12000; int led_fluo_pwm_channel = 0; int led_fluo_pwm_resolution = 8; // ~~~~ Commands ~~~~ const char *CMD; //Commands like: PXL -> limited to size of 3? int *INST[MAX_INST]; //Maximum number of possible instructions = std::vector INSTS; std::string CMDS; const char *COMMANDSET[NCOMMANDS] = {"DRVX", "DRVY", "DRVZ", "FLUO"}; const char *INSTRUCTS[NCOMMANDS] = {"1", "1", "1", "1"}; // ~~~~ FLUO ~~~~ int FLUO_STATUS = 0; // ---------------------------------------------------------------------------------------------------------------- // Additional Functions // Most stable and efficient way to have the ESP32 be active for input, but still wait (best for Android as well) void uc2wait(int period) { unsigned long time_now = millis(); while (millis() < time_now + period) { //wait approx. [period] ms }; } // Random-string generation from: https://stackoverflow.com/a/12468109 /*std::string random_string(size_t length) { auto randchar = []() -> char { const char charset[] = "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz"; const size_t max_index = (sizeof(charset) - 1); return charset[rand() % max_index]; }; std::string str(length, 0); std::generate_n(str.begin(), length, randchar); return str; }*/ void setup_device_properties() { //std::time_t result = std::time(nullptr); //srand(result); // init randomizer with pseudo-random seed on boot //int randnum = rand() % 10000; int rand_number = random(1, 100000); std::stringstream srn; srn << rand_number; DEVICENAME = DEVICE + "_" + srn.str(); // random number generated up to macro MAX_RAND CLIENTNAME = SETUP + "_" + COMPONENT + "_" + DEVICENAME; SETUP_INFO = "This is:" + DEVICENAME + " on /" + SETUP + "/" + COMPONENT + "."; MQTT_CLIENTID = DEVICENAME.c_str(); //"S1_MOT2_ESP32" //Serial.print("MQTT_CLIENTID=");Serial.println(MQTT_CLIENTID); MQTT_USER = DEVICE.c_str(); Serial.println(SETUP_INFO.c_str()); } void setup_wifi() { uc2wait(10); // We start by connecting to a WiFi network Serial.println(); Serial.print("Device-MAC: "); Serial.println(WiFi.macAddress()); Serial.print("Connecting to "); Serial.print(ssid); WiFi.setHostname(MQTT_CLIENTID); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { uc2wait(500); Serial.print("."); } Serial.println(""); Serial.print("WiFi connected with IP:"); Serial.println(WiFi.localIP()); } int separateMessage(byte *message, unsigned int length) { //Serial.println("Seperating Message."); //Serial.print("Message="); char messageSep[length]; for (int myc = 0; myc < length; myc++) { messageSep[myc] = (char)message[myc]; //Serial.print(messageSep[myc]); } messageSep[length] = NULL; //Serial.println(""); Serial.print("Mess="); std::string mess(messageSep); Serial.println(mess.c_str()); size_t pos = 0; int i = 0; bool found_cmd = false; while ((pos = mess.find(delim_inst)) != std::string::npos) { if (!found_cmd) { //Serial.print("CMD-del@"); //Serial.println(pos); CMDS = mess.substr(0, pos); //Serial.print("CMDS="); CMD = CMDS.c_str(); //Serial.println(CMD); found_cmd = true; } else { INSTS.push_back(atoi(mess.substr(0, pos).c_str())); //Serial.print("INST["); //Serial.print(i); //Serial.print("]="); //Serial.println(INSTS[i]); i++; } mess.erase(0, pos + delim_len); } if (!found_cmd) { //Serial.print("CMD-del@"); //Serial.println(pos); CMDS = mess.substr(0, pos); //Serial.print("CMDS="); CMD = CMDS.c_str(); //Serial.println(CMD); found_cmd = true; } else if (mess.length() > 0) { INSTS.push_back(atoi(mess.substr(0, pos).c_str())); //Serial.print("INST["); //Serial.print(i); //Serial.print("]="); //Serial.println(INSTS[i]); i++; } else { Serial.println("Nothing found..."); } return i; mess.clear(); } void callback(char *topic, byte *message, unsigned int length) { Serial.println("Callback-func called."); // test topics if (std::string(topic) == stopicREC) { //Serial.println(topicREC.c_str()); int nINST = separateMessage(message, length); if (strcmp(CMD, COMMANDSET[0]) == 0) { //Serial.print(INSTS[0] * 10); stepperX.Move((int)(INSTS[0] * 10)); } else if (strcmp(CMD, COMMANDSET[1]) == 0) { stepperY.Move((int)(INSTS[0] * 10)); } else if (strcmp(CMD, COMMANDSET[2]) == 0) { stepperZ.Move(INSTS[0] * 10); } else if (strcmp(CMD, COMMANDSET[3]) == 0) { //analogWrite(FLUO_PIN, INSTS[0]); ledcWrite(led_fluo_pwm_channel, INSTS[0]); } else { Serial.print("CMD not found."); } } else if (std::string(topic) == stopicSTATUS) { Serial.println(stopicSTATUS.c_str()); } else if (std::string(topic) == stopicANNOUNCE) { Serial.println(stopicANNOUNCE.c_str()); } else { Serial.print("Assortion Error: Nothing found for topic="); Serial.println(topic); } INSTS.clear(); } void reconnect() { // Loop until we're reconnected while (!client.connected()) { Serial.print("MQTT_CLIENTID="); Serial.println(MQTT_CLIENTID); Serial.print("topicSTATUS="); Serial.println(stopicSTATUS.c_str()); Serial.print("Attempting MQTT connection..."); // Attempt to connect if (client.connect(MQTT_CLIENTID, stopicSTATUS.c_str(), 2, 1, "0")) { // client.connect(MQTT_CLIENTID,MQTT_USER,MQTT_PASS,"esp32/on",2,1,"off") Serial.println("connected"); // Subscribe client.subscribe(stopicREC.c_str()); client.publish(stopicSTATUS.c_str(), "1"); client.publish(stopicANNOUNCE.c_str(), SETUP_INFO.c_str()); } else { Serial.print("failed, rc="); Serial.print(client.state()); Serial.println(" try again in 5 seconds"); // Wait 5 seconds before retrying uc2wait(5000); } } } // ---------------------------------------------------------------------------------------------------------------- // SETUP void setup() { Serial.begin(115200); // check for connected motors //status = bme.begin(); setup_device_properties(); Serial.print("VOID SETUP -> topicSTATUS="); Serial.println(stopicSTATUS.c_str()); setup_wifi(); Serial.print("Starting to connect MQTT to: "); Serial.print(MQTT_SERVER); Serial.print(" at port:"); Serial.println(MQTT_PORT); client.setServer(MQTT_SERVER, MQTT_PORT); client.setCallback(callback); pinMode(LED_BUILTIN, OUTPUT); time_now = millis(); //testCPP(); // ---> pinMode(LED_BUILTIN, OUTPUT); // ---> pinMode(LED_FLUO_PIN, OUTPUT); ledcSetup(led_fluo_pwm_channel, led_fluo_pwm_frequency, led_fluo_pwm_resolution); ledcAttachPin(LED_FLUO_PIN, led_fluo_pwm_channel); ledcWrite(led_fluo_pwm_channel, 20); //analogWrite(FLUO_PIN, 20); uc2wait(1000); ledcWrite(led_fluo_pwm_channel, 0); //analogWrite(FLUO_PIN, 0,0); uc2wait(100); stepperX.SetSpeed(10); stepperY.SetSpeed(10); stepperZ.SetSpeed(10); } // ---------------------------------------------------------------------------------------------------------------- // LOOP void loop() { if (!client.connected()) { reconnect(); } client.loop(); if (time_now + period < millis()) { client.publish(stopicSTATUS.c_str(), "1"); time_now = millis(); } } // ---------------------------------------------------------------------------------------------------------------- ```
click to show output ```cpp rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) flash read err, 1000 ets_main.c 371 ets Jun 8 2016 00:22:57 rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:1 load:0x3fff0018,len:4 load:0x3fff001c,len:1044 load:0x40078000,len:10124 load:0x40080400,len:5856 entry 0x400806a8 This is:ESP32_25717 on /S013/MOT01. VOID SETUP -> topicSTATUS=/S013/MOT01/STAT Device-MAC: 7C:9E:BD:06:F6:C8 Connecting to Kearney.. WiFi connected with IP:172.20.10.6 Starting to connect MQTT to: 172.20.10.5 at port:1883 MQTT_CLIENTID=ESP32_25717 topicSTATUS=/S013/MOT01/STAT Attempting MQTT connection... ```

Refer

I have search some reboot about esp. one is software contain a null point. two is the voltage is not enough. I am sure my vin power is fine. Thanks for looking.

BackMountainDevil commented 3 years ago

More info: I try to uncomment the things about matrix. Then it can connect my wifi and raspi normally.

part of the code Those command test both received by esp32. - `mosquitto_pub -t /S007/LAR01/RECM -m "test"` - `mosquitto_pub -t /S007/LAR01/RECM -m "PXL+20+127+255+50"` ```cpp void callback(char *topic, byte *message, unsigned int length) { Serial.println("Callback-func called."); // test topics if (std::string(topic) == stopicREC) { Serial.println(stopicREC.c_str()); int nINST = separateMessage(message, length); } else if (std::string(topic) == stopicSTATUS) { Serial.println(stopicSTATUS.c_str()); } else if (std::string(topic) == stopicANNOUNCE) { Serial.println(stopicANNOUNCE.c_str()); } else { Serial.print("Assortion Error: Nothing found for topic="); Serial.println(topic); } INSTS.clear(); } void setup() { Serial.begin(115200); // check for connected motors //status = bme.begin(); setup_device_properties(); Serial.print("VOID SETUP -> topicSTATUS="); Serial.println(stopicSTATUS.c_str()); setup_wifi(); Serial.print("Starting to connect MQTT to: "); Serial.print(MQTT_SERVER); Serial.print(" at port:"); Serial.println(MQTT_PORT); client.setServer(MQTT_SERVER, MQTT_PORT); client.setCallback(callback); pinMode(LED_BUILTIN, OUTPUT); time_now = millis(); //testCPP(); uc2wait(100); } ```
BackMountainDevil commented 3 years ago

At last, I found the code that wired. - portDISABLE_INTERRUPTS() and portENABLE_INTERRUPTS(). Comment them and the esp32 will not rebbot crazy. But I do not know if this is logical. I just find a fact that this work...

void matrix_show()
{
    // portDISABLE_INTERRUPTS(); // transmission to array should no be interrupted
    matrix.show();
    matrix.show();           // to remove glitchy green corner
    // portENABLE_INTERRUPTS(); // restore back interrupts
}
beniroquai commented 3 years ago

Hey @BackMountainDevil,

thanks for filing the issue! I could not reproduce this error. Which ESP did you use? Is there by any chance pin used twice? e.g. motorpin and ledpin? This often causes reboot issues. @renerichter any idea?

Best Bene

BackMountainDevil commented 3 years ago

Thank you for your reply. I see this esp32 in yout paper supplementary. My esp32 is the same ESP-WROOM-32 except the brand.

I use it with three pins: 3V3, GND, D23.
For reproduce this error. I do it again.

With my iphone hotspot off, output is keeping to try connect. More and more dots

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371 
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5856
entry 0x400806a8
This is:ESP32_75399 on /S007/LAR01.
VOID SETUP -> topicSTATUS=/S007/LAR01/STAT

Device-MAC: 7C:9E:BD:06:F6:C8
Connecting to Kearney.....................................................................

With my iphone hotspot on, it would conect wifi and get crazy reboot. Output is the same as two days before. Change another ESP-WROOM-32 or ESP 32S get the same result. Commet those two line in function matrix_show() will make it work with no crazy reboot. I use this new code test 4 ws1812 LED and it work. A new test will be done when I get a new 8x8 LED Matrix(The old one broke somehow) in few days.

beniroquai commented 3 years ago

Sounds good! Did you for some reason swap CMD with GND? This happened to me once and made problems..

BackMountainDevil commented 3 years ago

New 8x8 LED Matrix tested well. It seems that it is just cocidence.

beniroquai commented 3 years ago

Great! Thanks :-)

Am Sa., 11. Sept. 2021 um 04:31 Uhr schrieb Kearney < @.***>:

Closed #20 https://github.com/openUC2/UC2-Software-GIT/issues/20.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/openUC2/UC2-Software-GIT/issues/20#event-5287097124, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABBE5OFZAWL3DFZZJJDGR6LUBK5PJANCNFSM5A3QW44Q .