logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

ESP8266, secrets.h library: Usage, data storage, WiFi connection and ThingSpeak

TDA2593 1884 7
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 20599742
    TDA2593
    Level 9  
    Posts: 69
    Rate: 8
    Hello.
    Unfortunately I don't know how to deal with the library "secrets.h"?

    As far as I know "Secrets.h" is not a standard library in Arduino and I guess it can't be "normally" downloaded, installed. It allows to store confidential data in a special file.

    How to deal with it? How does it work.
    Can it be uncommented? Because I did, but I can't connect to the router.

    Here's the code and the page I'm using.

    https://makerslab.dev/kurs-esp-przesylanie-danych-do-chmury


    Code: Arduino
    Log in, to see the code


    Greetings.
  • ADVERTISEMENT
  • #2 20599804
    JacekCz
    Level 42  
    Posts: 8670
    Help: 760
    Rate: 1462
    Firstly, rarely is "xxxx.h" a library, even if all the holy arduino people say so.

    Secondly, if you ask a question and are genuinely interested in progressing in the thread, then paste the content, "something will be said".
  • ADVERTISEMENT
  • Helpful post
    #3 20599844
    gps79
    Level 37  
    Posts: 2190
    Help: 495
    Rate: 793
    If you're referring to this file (I'm guessing)
    https://github.com/mathworks/thingspeak-ardui...les/ArduinoMKR1000/WriteSingleField/secrets.h
    then you don't need it for anything, because you've revealed the "secret" data in the file you've attached.
    I recommend removing the #include "secrets.h" line from your code. You will not lose anything on the functionality of your program.
  • ADVERTISEMENT
  • #4 20599932
    JacekCz
    Level 42  
    Posts: 8670
    Help: 760
    Rate: 1462
    gps79 wrote:



    Sorry ...
    It's really Captain Kloss wouldn't be embarrassed ...

    If you guessed, and you probably did, I support the recommendation.

    Sorry, but the level of quality of the programming patterns that are communicated in the Arduino ...
  • #5 20601017
    TDA2593
    Level 9  
    Posts: 69
    Rate: 8
    Hi.

    Factually, I only needed to uncomment "secrets.h" in 2 places in the code.
    I did this earlier (as I wrote in the post), only I connected ESP to a router in the 5GHz band (similar network names) and that's where my problem arose.

    But how to correctly use and utilise this library I would be happy to learn.

    Greetings.
  • ADVERTISEMENT
  • #6 20601040
    gps79
    Level 37  
    Posts: 2190
    Help: 495
    Rate: 793
    Colleague @JacekCz in #2 asked for the contents of the file. We don't know what is in it. secrets.h is not a standard header. You haven't confirmed my assumption either. Let's not continue playing blind shooting.
  • #7 20601190
    jvoytech
    Level 22  
    Posts: 362
    Help: 61
    Rate: 136
    JacekCz wrote:
    First of all, rarely is "xxxx.h" a library, even if all the holy arduino people say so.

    A library can be a header and it is not that rare. There is nothing stopping you from putting everything into the file "xxxx.h" and including this file in your own project. You just need to use the appropriate macro instructions so that you don't have the problem of redefinitions.

    TDA2593 wrote:
    As far as I know "Secrets.h" is not a standard library in Arduino and I don't think it can be "normally" downloaded, installed. It allows to store confidential data in a special file.

    How to deal with it? How does it work
    Can it be uncommented? Because I did, but I can't connect to the router.

    The "secret.h" file is not a library but has a project configuration function implemented in a rather twisted and incorrect way. Generally such things are not placed in a repository and this file should be generated usually from the "secret.h.in" file where the placeholders are located. Such an example using cmake where from the file "config.h.in" with the following contents:
    Code: C / C++
    Log in, to see the code


    the file "config.h" is generated:
    Code: Objective-C
    Log in, to see the code

    This happens when using "cmake" for the first time and the name of this configuration file "config.h", should be found in ".gitignore". When using other tools (e.g. "./configure" from Autotools) this pattern "xxx.h.in -> xxx.h" is also used. Configurations could be entered from your finger as a macro when calling gcc, then you do not need to include "secret.h":
    Code: Bash
    Log in, to see the code


    this prevents sensitive data from being placed in the code, but with this way of configuring the project, it is worth ensuring that the compiler provides all the necessary macros, e.g. something like this:
    Code: C / C++
    Log in, to see the code



    The ArduinoIDE is crippled and there is rather no option to generate the appropriate configuration for the project and ask the user for data. That's why in the "examples" for a given library there should be a tutorial on how to create such a file and inform the user not to smoke a fool and put it in the repository.
  • #8 20601237
    JacekCz
    Level 42  
    Posts: 8670
    Help: 760
    Rate: 1462
    jvoytech wrote:
    JacekCz wrote:
    First of all, rarely is "xxxx.h" a library, even though all the holy arduino people would say so.

    A library can be a header and this is not that rare. Nothing prevents you from putting everything into the file "xxxx.h" and including this file in your own project. You just need to use the appropriate macro instructions so that you don't have the problem of redefinitions.


    And this is the maximum "security" you can squeeze out of yourself in the Arduino.

    Meanwhile, many libraries (bibliotus, one header) base the file name / main class / variable (oh! a variable in a library, one of the more brilliant ideas) on the main ABC_1234 chip it is trying to support. 1/3 of the trouble here, is the adept combining two "codes" (I love the word "codes" plural) and coming into conflict.
    And such a beautiful C++ "security" as namespace is unknown to prominent arduino programmers, devil vs holy water.

    Following this is the common patient talk of library name as header file name, no author name, no github link, nothing, "no distinction in reasoning". *).
    I definitely think so, people are as weak as the content they are fed. When you unreflectively copy random search results, you don't know where you're copying from.

    *) https://www.elektroda.pl/rtvforum/topic3407648.html#16885936

    Added after 15 [minutes]:


    jvoytech wrote:
    The ArduinoIDE is crippled and there is unlikely to be an option for

    This is just a minor addition to bad patterns.
    There is no need in the community -> IDE doesn't get the fizz.

Topic summary

✨ The discussion revolves around the usage of the "secrets.h" library in conjunction with the ESP8266 microcontroller for WiFi connectivity and data transmission to ThingSpeak. The user initially struggles with the library, questioning its necessity and functionality. Responses clarify that "secrets.h" is not a standard Arduino library and suggest removing it if the secret data is exposed. The user later identifies that the connection issue stemmed from using a 5GHz WiFi band. The conversation highlights the importance of understanding library configurations and the potential pitfalls of using non-standard libraries in Arduino projects.
Generated by the language model.

FAQ

TL;DR: 15 pytań, „secrets.h to konfiguracja”, nie standardowa biblioteka Arduino: FAQ pomaga użytkownikom ESP8266 naprawić WiFi, uporządkować hasła, klucze ThingSpeak i wysyłkę DS18B20 bez mieszania danych tajnych z kodem programu. [#20601190] Dlaczego to ważne: Błędne użycie secrets.h ukrywa prosty problem: ESP8266 nie połączy się z siecią 5 GHz, nawet gdy kod i hasło wyglądają poprawnie.

Podejście Co zawiera Skutek w szkicu ESP8266
secrets.h Makra typu SECRET_SSID, SECRET_PASS Oddziela konfigurację od kodu, jeśli szkic używa tych nazw
Dane w kodzie ssid, pass, numer kanału, klucz API #include "secrets.h" nie jest potrzebny, gdy wszystkie dane są już jawnie wpisane
Makra kompilatora -D Wartości przekazane przy wywołaniu gcc Może zastąpić plik nagłówkowy w projektach C/C++

Kluczowa obserwacja: secrets.h sam nie łączy z WiFi i sam nie zabezpiecza projektu. Szkic musi konsekwentnie używać tych samych nazw, na przykład SECRET_SSID i SECRET_PASS, albo jawnych zmiennych ssid i pass.

Quick Facts

  • ESP8266 w opisanym przypadku nie łączył się, bo użytkownik wybrał pasmo 5 GHz przy podobnych nazwach sieci; problem nie wynikał z ThingSpeak. [#20601017]
  • Kod inicjuje port szeregowy z prędkością 9600, próbuje WiFi co 5000 ms i wysyła dane co 20000 ms. [#20599742]
  • ThingSpeak w szkicu dostaje 2 pola: temperaturę z DS18B20 oraz liczbę losową z zakresu 0–100. [#20599742]
  • Minimalny odstęp wysyłania wpisany w komentarzu wynosi 15 s, a szkic używa bezpieczniejszego opóźnienia 20 s. [#20599742]
  • secrets.h nie jest standardowym nagłówkiem Arduino; bez pokazania jego zawartości diagnoza staje się „strzelaniem na ślepo”. [#20601040]

Czym jest secrets.h w projektach Arduino i ESP8266 oraz dlaczego przykłady używają go dla haseł WiFi i kluczy API?

secrets.h jest plikiem konfiguracyjnym projektu, nie standardową biblioteką Arduino. "secrets.h jest plikiem nagłówkowym, który przechowuje makra konfiguracyjne, zwykle SSID, hasło WiFi i klucze API, aby nie wpisywać ich bezpośrednio w głównym szkicu." W wątku wskazano, że przykłady używają go dla danych takich jak SECRET_SSID i SECRET_PASS. Plik działa tylko wtedy, gdy kod odwołuje się do tych samych nazw makr. [#20601190]

Jak poprawnie utworzyć i użyć pliku secrets.h z ESP8266, ThingSpeak i Arduino IDE?

Utwórz secrets.h w tym samym projekcie i zdefiniuj w nim dane używane przez szkic. 1. Dodaj #include "secrets.h" na początku programu. 2. W pliku wpisz makra, na przykład SECRET_SSID i SECRET_PASS. 3. W kodzie używaj WiFi.begin(SECRET_SSID, SECRET_PASS), a nie innych zmiennych. Arduino IDE nie generuje takiej konfiguracji automatycznie, więc użytkownik tworzy plik ręcznie. [#20601190]

Dlaczego usunięcie #include "secrets.h" nie psuje szkicu ESP8266, gdy SSID, hasło, numer kanału i klucz API ThingSpeak są już wpisane bezpośrednio w kodzie?

Usunięcie #include "secrets.h" nie psuje szkicu, gdy kod nie potrzebuje definicji z tego pliku. W pokazanym programie ssid, pass, myChannelNumber i myWriteAPIKey są już wpisane jawnie. Dlatego funkcja WiFi.begin(ssid, pass) ma komplet danych. Jeden z uczestników zalecił usunięcie tej dyrektywy, bo „sekretne” dane były już ujawnione w szkicu. [#20599844]

Jak zdefiniować SECRET_SSID i SECRET_PASS w secrets.h dla przykładu Arduino z ThingSpeak?

Zdefiniuj SECRET_SSID i SECRET_PASS jako makra tekstowe używane przez szkic. Przykład z wątku pokazuje wzorzec sprawdzający obecność obu nazw: #if !defined(SECRET_SSID) || !defined(SECRET_PASS). Gdy brakuje jednego makra, kompilator może zatrzymać budowanie komunikatem błędu. Warto zachować dokładnie te nazwy, bo SECRET_SSID i ssid to 2 różne identyfikatory. [#20601190]

Dlaczego ESP8266 może nie połączyć się z WiFi, gdy router ma podobne nazwy sieci 2,4 GHz i 5 GHz?

ESP8266 może utknąć przy łączeniu, gdy użytkownik wybierze sieć 5 GHz zamiast właściwej sieci 2,4 GHz. Autor wątku znalazł właśnie taki błąd: podobne nazwy sieci doprowadziły do połączenia z pasmem 5 GHz. Po korekcie okazało się, że secrets.h nie był główną przyczyną problemu. To typowy przypadek, gdy poprawne hasło nie wystarcza. [#20601017]

Jak diagnozować ESP8266, który bez końca drukuje kropki podczas łączenia przez WiFi.begin(ssid, pass)?

Sprawdź najpierw sieć, nazwy zmiennych i realne dane logowania. Kod z wątku drukuje kropkę co 5000 ms, dopóki WiFi.status() nie zwróci połączenia. Używa też WiFi.begin(ssid, pass), więc SECRET_SSID w samym komunikacie szeregowym nie wpływa na logowanie. Edge case: podobna nazwa sieci 5 GHz może wyglądać poprawnie, ale ESP8266 nadal nie połączy się z wybraną siecią. [#20599742]

Jaka jest różnica między plikiem nagłówkowym a biblioteką w Arduino C++?

Plik nagłówkowy to nie zawsze pełna biblioteka, choć może zawierać cały kod. "Plik nagłówkowy jest plikiem C/C++, który dołącza deklaracje, makra lub definicje do projektu, zwykle przez #include, a przy złej organizacji może powodować redefinicje." W dyskusji podkreślono, że xxxx.h bywa błędnie nazywany biblioteką. Inny uczestnik dodał, że biblioteka może składać się tylko z jednego nagłówka, jeśli stosuje właściwe zabezpieczenia. [#20601190]

secrets.h kontra hasła wpisane na stałe w szkicu Arduino — które podejście jest lepsze dla haseł WiFi i kluczy API ThingSpeak?

Lepsze jest oddzielenie haseł i kluczy od głównego szkicu, jeśli projekt ma być kopiowany lub wersjonowany. Wpisanie danych w kod działa technicznie, ale ujawnia SSID, hasło oraz klucz API w jednym pliku. secrets.h porządkuje konfigurację, lecz nadal wymaga ostrożności. W wątku wskazano, że taki plik nie powinien trafiać do repozytorium. [#20601190]

Czym jest ThingSpeak i jak ESP8266 wysyła dane z czujnika do kanału ThingSpeak?

ThingSpeak odbiera dane przez bibliotekę ThingSpeak.h i zapisuje je w polach kanału. W szkicu ESP8266 tworzy WiFiClient, wywołuje ThingSpeak.begin(client), ustawia field 1 i field 2, a potem używa ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey). Sukces oznacza kod 200. Program wysyła aktualizację co 20 s, zgodnie z komentarzem o minimum 15 s. [#20599742]

Jak wysłać odczyty temperatury DS18B20 z ESP8266 do ThingSpeak przy użyciu OneWire i DallasTemperature?

Podłącz DS18B20 do magistrali OneWire i wyślij temperaturę jako pole ThingSpeak. W kodzie magistrala używa pinu D2, biblioteki OneWire oraz DallasTemperature. Program wywołuje sensors.requestTemperatures(), odczytuje sensors.getTempC(sensor) i przypisuje wynik do number1. Następnie ThingSpeak.setField(1, number1) umieszcza temperaturę w pierwszym polu kanału. [#20599742]

Czym jest plik .gitignore i dlaczego secrets.h lub config.h powinny być wykluczone z repozytorium Git?

.gitignore wskazuje pliki, których Git nie powinien dodawać do repozytorium. ".gitignore jest plikiem konfiguracyjnym Git, który opisuje ignorowane ścieżki, aby prywatne lub generowane pliki, takie jak config.h, nie trafiły do historii projektu." W wątku wskazano, że wygenerowany config.h powinien znaleźć się w .gitignore. To ogranicza przypadkowe ujawnienie danych konfiguracyjnych. [#20601190]

Czym jest config.h.in i jak służy do generowania config.h w projektach CMake lub Autotools?

config.h.in jest szablonem, z którego narzędzie budujące generuje config.h. "config.h.in jest szablonem konfiguracji C/C++, który zawiera znaczniki zastępcze, a CMake lub Autotools zamieniają je na konkretne definicje podczas pierwszej konfiguracji projektu." W przykładzie #cmakedefine FOO_ENABLE i @FOO_STRING@ tworzą potem #define FOO_ENABLE oraz #define FOO_STRING "foo". [#20601190]

Jak makra kompilatora typu -DSECRET_SSID i -DSECRET_PASS mogą zastąpić plik secrets.h w projektach embedded C/C++?

Makra -D przekazują konfigurację bez osobnego pliku secrets.h. W wątku podano przykład wywołania gcc -DSECRET_SSID="1234567" -DSECRET_PASS="wifi_haslo" .... Taki sposób definiuje wartości podczas kompilacji, zanim kod użyje tych nazw. Działa w projektach C/C++, gdzie system budowania pozwala dopisać flagi kompilatora. [#20601190]

Co robi błąd preprocesora Arduino #error, gdy brakuje wymaganych makr, takich jak SECRET_SSID lub SECRET_PASS?

Dyrektywa #error zatrzymuje kompilację z własnym komunikatem. W przykładzie z wątku kod sprawdza 2 makra: SECRET_SSID i SECRET_PASS. Jeśli któregokolwiek brakuje, preprocesor zgłasza komunikat: please define macro SECRET_SSID and SECRET_PASS in secret.h header file. To wykrywa złą konfigurację przed uruchomieniem ESP8266. [#20601190]

Jakie są najlepsze praktyki bezpiecznego przechowywania haseł WiFi i kluczy API w projektach Arduino IDE dla ESP8266?

Trzymaj dane logowania poza głównym szkicem i nie publikuj ich w repozytorium. Użyj secrets.h z makrami, dodaj kontrolę #if !defined(...), a plik z rzeczywistymi wartościami wyklucz z Git. W Arduino IDE tworzysz taki plik ręcznie, bo środowisko nie generuje konfiguracji projektu jak CMake. Jeśli dane są już wpisane w kod, secrets.h nie zwiększa bezpieczeństwa. [#20601190]
Generated by the language model.
ADVERTISEMENT