sinricpro / esp8266-esp32-sdk

Library for https://sinric.pro - simple way to connect your device to Alexa, Google Home, SmartThings and cloud
https://sinric.pro
Other
234 stars 124 forks source link

program esp32 #317

Closed lakshkunde closed 1 year ago

lakshkunde commented 1 year ago

I am not able to program the esp32 board with Arduino and make home automation system

sivar2311 commented 1 year ago

Not enough information for an analysis.

sivar2311 commented 1 year ago

@lakshkunde Please provide detailed information such as error messages, logs and/or screenshots.

lakshkunde commented 1 year ago

ok it says :- Arduino: 1.8.5 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

Build options changed, rebuilding all C:\Users\ADMIN\Desktop\Code_NodeMCU_Google_Alexa_SinricPro_4Relay_Switch\Code_NodeMCU_Google_Alexa_SinricPro_4Relay_Switch.ino:38:10: fatal error: SinricPro.h: No such file or directory 38 | #include "SinricPro.h" | ^~~~~ compilation terminated.

exit status 1 Error compiling for board NodeMCU 1.0 (ESP-12E Module).

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

sivar2311 commented 1 year ago

fatal error: SinricPro.h: No such file or directory

You have to install the library and it's dependencies first! Please see here

lakshkunde commented 1 year ago

i will get to you soon

lakshkunde commented 1 year ago

2 min

lakshkunde commented 1 year ago

should i send you the code

lakshkunde commented 1 year ago

/**

// Uncomment the following line to enable serial debug output //#define ENABLE_DEBUG

ifdef ENABLE_DEBUG

   #define DEBUG_ESP_PORT Serial
   #define NODEBUG_WEBSOCKETS
   #define NDEBUG

endif

include

include

include "SinricPro.h"

include "SinricProSwitch.h"

include

define WIFI_SSID "Cambridge_EXT"

define WIFI_PASS "L@ksh2009"

define APP_KEY "1d742bec-ae35-490d-8dfc-17f06cb41a68" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"

define APP_SECRET "2a0ae3c7-380d-47a4-8bbd-0759f5ec5544-24c7abf7-b006-466d-bb96-9b61b879e6f5" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"

//Enter the device IDs here

define device_ID_1 "xxxxxxxxxxxxxxxxxxxxxxxx"

define device_ID_2 "641da4920f750d41bd14fae0"

define device_ID_3 "641da4ea0f750d41bd14fb5f"

define device_ID_4 "641da3a40f750d41bd14f9a2"

// define the GPIO connected with Relays and switches

define RelayPin1 5 //D1

define RelayPin2 4 //D2

define RelayPin3 14 //D5

define RelayPin4 12 //D6

define SwitchPin1 10 //SD3

define SwitchPin2 0 //D3

define SwitchPin3 13 //D7

define SwitchPin4 3 //RX

define wifiLed 16 //D0

// comment the following line if you use a toggle switches instead of tactile buttons //#define TACTILE_BUTTON 1

define BAUD_RATE 9600

define DEBOUNCE_TIME 250

typedef struct { // struct for the std::map below int relayPIN; int flipSwitchPIN; } deviceConfig_t;

// this is the main configuration // please put in your deviceId, the PIN for Relay and PIN for flipSwitch // this can be up to N devices...depending on how much pin's available on your device ;) // right now we have 4 devicesIds going to 4 relays and 4 flip switches to switch the relay manually std::map<String, deviceConfig_t> devices = { //{deviceId, {relayPIN, flipSwitchPIN}} {device_ID_1, { RelayPin1, SwitchPin1 }}, {device_ID_2, { RelayPin2, SwitchPin2 }}, {device_ID_3, { RelayPin3, SwitchPin3 }}, {device_ID_4, { RelayPin4, SwitchPin4 }}
};

typedef struct { // struct for the std::map below String deviceId; bool lastFlipSwitchState; unsigned long lastFlipSwitchChange; } flipSwitchConfig_t;

std::map<int, flipSwitchConfig_t> flipSwitches; // this map is used to map flipSwitch PINs to deviceId and handling debounce and last flipSwitch state checks // it will be setup in "setupFlipSwitches" function, using informations from devices map

void setupRelays() { for (auto &device : devices) { // for each device (relay, flipSwitch combination) int relayPIN = device.second.relayPIN; // get the relay pin pinMode(relayPIN, OUTPUT); // set relay pin to OUTPUT digitalWrite(relayPIN, HIGH); } }

void setupFlipSwitches() { for (auto &device : devices) { // for each device (relay / flipSwitch combination) flipSwitchConfig_t flipSwitchConfig; // create a new flipSwitch configuration

flipSwitchConfig.deviceId = device.first;         // set the deviceId
flipSwitchConfig.lastFlipSwitchChange = 0;        // set debounce time
flipSwitchConfig.lastFlipSwitchState = true;     // set lastFlipSwitchState to false (LOW)--

int flipSwitchPIN = device.second.flipSwitchPIN;  // get the flipSwitchPIN

flipSwitches[flipSwitchPIN] = flipSwitchConfig;   // save the flipSwitch config to flipSwitches map
pinMode(flipSwitchPIN, INPUT_PULLUP);                   // set the flipSwitch pin to INPUT

} }

bool onPowerState(String deviceId, bool &state) { Serial.printf("%s: %s\r\n", deviceId.c_str(), state ? "on" : "off"); int relayPIN = devices[deviceId].relayPIN; // get the relay pin for corresponding device digitalWrite(relayPIN, !state); // set the new relay state return true; }

void handleFlipSwitches() { unsigned long actualMillis = millis(); // get actual millis for (auto &flipSwitch : flipSwitches) { // for each flipSwitch in flipSwitches map unsigned long lastFlipSwitchChange = flipSwitch.second.lastFlipSwitchChange; // get the timestamp when flipSwitch was pressed last time (used to debounce / limit events)

if (actualMillis - lastFlipSwitchChange > DEBOUNCE_TIME) {                    // if time is > debounce time...

  int flipSwitchPIN = flipSwitch.first;                                       // get the flipSwitch pin from configuration
  bool lastFlipSwitchState = flipSwitch.second.lastFlipSwitchState;           // get the lastFlipSwitchState
  bool flipSwitchState = digitalRead(flipSwitchPIN);                          // read the current flipSwitch state
  if (flipSwitchState != lastFlipSwitchState) {                               // if the flipSwitchState has changed...

ifdef TACTILE_BUTTON

    if (flipSwitchState) {                                                    // if the tactile button is pressed 

endif

      flipSwitch.second.lastFlipSwitchChange = actualMillis;                  // update lastFlipSwitchChange time
      String deviceId = flipSwitch.second.deviceId;                           // get the deviceId from config
      int relayPIN = devices[deviceId].relayPIN;                              // get the relayPIN from config
      bool newRelayState = !digitalRead(relayPIN);                            // set the new relay State
      digitalWrite(relayPIN, newRelayState);                                  // set the trelay to the new state

      SinricProSwitch &mySwitch = SinricPro[deviceId];                        // get Switch device from SinricPro
      mySwitch.sendPowerStateEvent(!newRelayState);                            // send the event

ifdef TACTILE_BUTTON

    }

endif

    flipSwitch.second.lastFlipSwitchState = flipSwitchState;                  // update lastFlipSwitchState
  }
}

} }

void setupWiFi() { Serial.printf("\r\n[Wifi]: Connecting"); WiFi.begin(WIFI_SSID, WIFI_PASS);

while (WiFi.status() != WL_CONNECTED) { Serial.printf("."); delay(250); } digitalWrite(wifiLed, LOW); Serial.printf("connected!\r\n[WiFi]: IP-Address is %s\r\n", WiFi.localIP().toString().c_str()); }

void setupSinricPro() { for (auto &device : devices) { const char *deviceId = device.first.c_str(); SinricProSwitch &mySwitch = SinricPro[deviceId]; mySwitch.onPowerState(onPowerState); }

SinricPro.begin(APP_KEY, APP_SECRET); SinricPro.restoreDeviceStates(true); }

void setup() { Serial.begin(BAUD_RATE);

pinMode(wifiLed, OUTPUT); digitalWrite(wifiLed, HIGH);

setupRelays(); setupFlipSwitches(); setupWiFi(); setupSinricPro(); }

void loop() { SinricPro.handle(); handleFlipSwitches(); }

lakshkunde commented 1 year ago

this is the code

sivar2311 commented 1 year ago

No, you have to install the library (and dependent libraries) before you can use it. See here how to install the libraries in ArduinoIDE

lakshkunde commented 1 year ago

I completed the hardware part and I am stuck on the programming part

lakshkunde commented 1 year ago

ok wait for 2 min

lakshkunde commented 1 year ago

This is the video link from which I am making the project:- https://www.youtube.com/watch?v=gpB4600keWA

sivar2311 commented 1 year ago

Looks like you missed this part in the video. Check 6:02 in the video: https://youtu.be/gpB4600keWA?t=362

lakshkunde commented 1 year ago

ok I will repeat the process

lakshkunde commented 1 year ago

2 min

lakshkunde commented 1 year ago

thank you very very very much you have helped me a lot thank you and to inform you I am 13-year-old boy which is now taking to you