8
« kdy: 08. 07. 2024, 19:56:50 »
Zabavam sa s ESP32. Programujem to cez Arduino IDE a narazil som na problem.
Rad by som poslal zaznam ze na danom pine sa zmenil signal cez HTTP request.
#include <WiFi.h>
#include <WebServer.h>
#include <FastLED.h>
#include <EEPROM.h>
#include <HTTPClient.h>
// Definície k LED pásu
#define NUM_LEDS 42
#define LED_PIN 2
#define LED_TYPE WS2813
#define COLOR_ORDER GRB
#define BRIGHTNESS 100
CRGB leds[NUM_LEDS];
// Nastavenia pre webserver
char ssid[32] = "xxx";
char password[32] = "sss";
WebServer server(80);
// EEPROM address definitions
#define EEPROM_SIZE 512
#define IP_ADDR_START 0
#define SEGMENT_COLORS_START 16
#define SEGMENT_RANGES_START 64
#define SEGMENT_POLARITY 128
#define WIFI_CREDENTIALS_START 256
#define MONITOR_PIN14_ADDR 320
String HOST_NAME = "http://192.168.0.7";
String PHP_FILE_NAME = "/insert_data.php";
String tempQuery = "?temperature=31.0";
IPAddress staticIP(192, 168, 0, 50); // Default static IP address
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress apIP(192, 168, 0, 50); // IP address for AP mode
IPAddress apGateway(192, 168, 0, 1);
IPAddress apSubnet(255, 255, 255, 0);
const int segmentPins[] = { 14, 27, 26, 25, 33, 32 };
CRGB segmentColors[] = { CRGB::Orange, CRGB::Blue, CRGB::Green, CRGB::Red, CRGB::Purple, CRGB::Yellow };
int segmentRanges[][2] = { { 1, 7 }, { 8, 14 }, { 15, 21 }, { 22, 28 }, { 29, 35 }, { 36, 42 } };
bool polarity[] = { false, false, false, false, false, false };
bool monitorPin14 = false;
int lastPin14State = LOW;
------
void loop() {
server.handleClient();
for (int i = 0; i < 6; i++) {
controlSegmentPower(segmentPins[i], segmentColors[i], segmentRanges[i][0], segmentRanges[i][1], polarity[i]);
}
}
void controlSegmentPower(int segmentPin, CRGB segmentColor, int startIndex, int endIndex, bool polarity) {
if (monitorPin14 and segmentPin == 14) {
// Monitor Pin 14 logic
int currentPin14State = digitalRead(14);
Serial.println(currentPin14State);
if (currentPin14State != lastPin14State) {
if (currentPin14State == LOW) {
sendHTTPRequest(); // Call function to send HTTP request
}
lastPin14State = currentPin14State;
}
}
if (polarity == false) {
if (digitalRead(segmentPin) == HIGH) {
delay(100);
for (int i = startIndex; i <= endIndex; i++) {
leds[i] = segmentColor;
}
} else {
for (int i = startIndex; i <= endIndex; i++) {
leds[i] = CRGB::Black;
}
}
} else {
if (digitalRead(segmentPin) == LOW) {
delay(100);
for (int i = startIndex; i <= endIndex; i++) {
leds[i] = segmentColor;
}
} else {
for (int i = startIndex; i <= endIndex; i++) {
leds[i] = CRGB::Black;
}
}
}
FastLED.show();
delay(100);
}
void sendHTTPRequest() {
try {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String url = HOST_NAME + PHP_FILE_NAME + tempQuery;
Serial.println("URL: " + url);
http.begin(url.c_str());
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
Serial.println("Response payload: " + payload);
} else {
Serial.println("Error on HTTP request");
}
http.end();
} else {
Serial.println("WiFi not connected");
}
} catch (const std::exception &e) {
Serial.println("Exception occurred: " + String(e.what()));
} catch (...) {
Serial.println("Unknown exception occurred");
}
}
Problem je ze vzdy ked by mal poslat request ze sa nieco zmenilo tak to cele spadne.
19:28:00.237 -> EXCVADDR: 0x00000014 LBEG : 0x40084c19 LEND : 0x40084c21 LCOUNT : 0x00000027
19:28:00.333 ->
19:28:00.333 ->
19:28:00.333 -> Backtrace: 0x400e0552:0x3ffb2170 0x400e061d:0x3ffb2190 0x400e0657:0x3ffb21e0 0x400e0680:0x3ffb2200 0x400d4cf8:0x3ffb2220 0x400d55d7:0x3ffb2250 0x400e2ef8:0x3ffb2270 0x400906a6:0x3ffb2290
19:28:00.526 ->
19:28:00.526 ->
19:28:00.526 ->
Ani google mi nepomohol ani chatGPT. Kde je zrada? Ma niekto skusenost?