Englebert
3 years ago
commit
5d6c23daf1
9 changed files with 232 additions and 0 deletions
-
1.gitignore
-
39include/README
-
46lib/README
-
22platformio.ini
-
16src/main.cpp
-
3src/main.h
-
71src/wifi.cpp
-
23src/wifi.h
-
11test/README
@ -0,0 +1 @@ |
|||
.pio |
@ -0,0 +1,39 @@ |
|||
|
|||
This directory is intended for project header files. |
|||
|
|||
A header file is a file containing C declarations and macro definitions |
|||
to be shared between several project source files. You request the use of a |
|||
header file in your project source file (C, C++, etc) located in `src` folder |
|||
by including it, with the C preprocessing directive `#include'. |
|||
|
|||
```src/main.c |
|||
|
|||
#include "header.h" |
|||
|
|||
int main (void) |
|||
{ |
|||
... |
|||
} |
|||
``` |
|||
|
|||
Including a header file produces the same results as copying the header file |
|||
into each source file that needs it. Such copying would be time-consuming |
|||
and error-prone. With a header file, the related declarations appear |
|||
in only one place. If they need to be changed, they can be changed in one |
|||
place, and programs that include the header file will automatically use the |
|||
new version when next recompiled. The header file eliminates the labor of |
|||
finding and changing all the copies as well as the risk that a failure to |
|||
find one copy will result in inconsistencies within a program. |
|||
|
|||
In C, the usual convention is to give header files names that end with `.h'. |
|||
It is most portable to use only letters, digits, dashes, and underscores in |
|||
header file names, and at most one dot. |
|||
|
|||
Read more about using header files in official GCC documentation: |
|||
|
|||
* Include Syntax |
|||
* Include Operation |
|||
* Once-Only Headers |
|||
* Computed Includes |
|||
|
|||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html |
@ -0,0 +1,46 @@ |
|||
|
|||
This directory is intended for project specific (private) libraries. |
|||
PlatformIO will compile them to static libraries and link into executable file. |
|||
|
|||
The source code of each library should be placed in a an own separate directory |
|||
("lib/your_library_name/[here are source files]"). |
|||
|
|||
For example, see a structure of the following two libraries `Foo` and `Bar`: |
|||
|
|||
|--lib |
|||
| | |
|||
| |--Bar |
|||
| | |--docs |
|||
| | |--examples |
|||
| | |--src |
|||
| | |- Bar.c |
|||
| | |- Bar.h |
|||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html |
|||
| | |
|||
| |--Foo |
|||
| | |- Foo.c |
|||
| | |- Foo.h |
|||
| | |
|||
| |- README --> THIS FILE |
|||
| |
|||
|- platformio.ini |
|||
|--src |
|||
|- main.c |
|||
|
|||
and a contents of `src/main.c`: |
|||
``` |
|||
#include <Foo.h> |
|||
#include <Bar.h> |
|||
|
|||
int main (void) |
|||
{ |
|||
... |
|||
} |
|||
|
|||
``` |
|||
|
|||
PlatformIO Library Dependency Finder will find automatically dependent |
|||
libraries scanning project source files. |
|||
|
|||
More information about PlatformIO Library Dependency Finder |
|||
- https://docs.platformio.org/page/librarymanager/ldf.html |
@ -0,0 +1,22 @@ |
|||
; PlatformIO Project Configuration File |
|||
; |
|||
; Build options: build flags, source filter |
|||
; Upload options: custom upload port, speed and extra flags |
|||
; Library options: dependencies, extra library storages |
|||
; Advanced options: extra scripting |
|||
; |
|||
; Please visit documentation for the other options and examples |
|||
; https://docs.platformio.org/page/projectconf.html |
|||
|
|||
[env:esp32dev] |
|||
platform = espressif32 |
|||
board = esp32dev |
|||
framework = arduino |
|||
upload_speed = 460800 |
|||
|
|||
; Custom CPU Frequency |
|||
board_build.f_cpu = 240000000L |
|||
board_build.f_flash = 40000000L |
|||
|
|||
; 16MB Flash |
|||
board_build.partitions = default_16MB.csv |
@ -0,0 +1,16 @@ |
|||
#include "Arduino.h"
|
|||
|
|||
void setup() { |
|||
Serial.begin(115200); |
|||
Serial.print("FREE RAM: "); Serial.print(ESP.getFreeHeap()); Serial.println(" MB"); |
|||
|
|||
uint32_t ideSize = ESP.getFlashChipSize(); |
|||
FlashMode_t ideMode = ESP.getFlashChipMode(); |
|||
|
|||
Serial.printf("Flash ide size: %u bytes\n", ideSize); |
|||
Serial.printf("Flash ide speed: %u Hz\n", ESP.getFlashChipSpeed()); |
|||
Serial.printf("Flash ide mode: %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN")); |
|||
} |
|||
|
|||
void loop() { |
|||
} |
@ -0,0 +1,3 @@ |
|||
#ifndef MAIN_H |
|||
#define MAIN_H |
|||
#endif |
@ -0,0 +1,71 @@ |
|||
#include "wifi.h"
|
|||
#include "main.h"
|
|||
|
|||
WIFI::WIFI(void) { |
|||
// pinMode(WIFI_INDICATOR, OUTPUT);
|
|||
} |
|||
|
|||
void WIFI::set_credential(char *ssid, char *passphrase) { |
|||
strcpy(WIFI::_ssid, ssid); |
|||
strcpy(WIFI::_passphrase, passphrase); |
|||
|
|||
// Initial value
|
|||
this->wifi_check_duration = 5000; |
|||
} |
|||
|
|||
void WIFI::connect_wifi(void) { |
|||
if(strlen(WIFI::_ssid) == 0) { |
|||
// Serial.println("(wifi) Empty SSID");
|
|||
return; |
|||
} |
|||
|
|||
if(WiFi.status() == WL_CONNECTED) { |
|||
WiFi.disconnect(); |
|||
} |
|||
|
|||
// WiFi.begin(this->_ssid, this->_passphrase);
|
|||
WiFi.begin(WIFI::_ssid, WIFI::_passphrase); |
|||
} |
|||
|
|||
bool WIFI::check_wifi(void) { |
|||
bool ret_val = false; |
|||
|
|||
if( |
|||
(uint32_t)(millis() - last_wifi_check) > wifi_check_duration |
|||
){ |
|||
if(WiFi.status() != WL_CONNECTED) { |
|||
Serial.println(F("WiFi Connecting")); |
|||
WiFi.disconnect(); |
|||
|
|||
// GPIO.out_w1tc = ((uint32_t)1 << WIFI_INDICATOR);
|
|||
|
|||
// WiFi.begin(this->_ssid, this->_passphrase);
|
|||
// Serial.print("(check_wifi)->SSID : "); Serial.println(WIFI::_ssid);
|
|||
// Serial.print("(check_wifi)->PASSPHRASE: "); Serial.println(WIFI::_passphrase);
|
|||
|
|||
WIFI::connect_wifi(); |
|||
wifi_check_duration = 5000; |
|||
ret_val = false; |
|||
} else { |
|||
// GPIO.out_w1ts = ((uint32_t)1 << WIFI_INDICATOR);
|
|||
|
|||
Serial.println(F("WiFi OK")); |
|||
|
|||
Serial.print(F("IP: ")); |
|||
Serial.println(WiFi.localIP()); |
|||
wifi_check_duration = 60000; |
|||
ret_val = true; |
|||
} |
|||
|
|||
last_wifi_check = millis(); |
|||
} |
|||
|
|||
return ret_val; |
|||
} |
|||
|
|||
bool WIFI::is_connected(void) { |
|||
if(WiFi.status() == WL_CONNECTED) |
|||
return true; |
|||
else |
|||
return false; |
|||
} |
@ -0,0 +1,23 @@ |
|||
#ifndef WIFI_H_ |
|||
#define WIFI_H_ |
|||
|
|||
#include <Arduino.h> |
|||
#include <WiFi.h> |
|||
#include <WiFiClient.h> |
|||
|
|||
// #define WIFI_INDICATOR 2 |
|||
|
|||
class WIFI { |
|||
public: |
|||
WIFI(void); |
|||
void set_credential(char *ssid, char *passphrase); |
|||
void connect_wifi(void); |
|||
bool check_wifi(void); |
|||
bool is_connected(void); |
|||
char _ssid[32], _passphrase[32]; |
|||
|
|||
private: |
|||
uint32_t last_wifi_check, wifi_check_duration; |
|||
}; |
|||
|
|||
#endif |
@ -0,0 +1,11 @@ |
|||
|
|||
This directory is intended for PlatformIO Unit Testing and project tests. |
|||
|
|||
Unit Testing is a software testing method by which individual units of |
|||
source code, sets of one or more MCU program modules together with associated |
|||
control data, usage procedures, and operating procedures, are tested to |
|||
determine whether they are fit for use. Unit testing finds problems early |
|||
in the development cycle. |
|||
|
|||
More information about PlatformIO Unit Testing: |
|||
- https://docs.platformio.org/page/plus/unit-testing.html |
Write
Preview
Loading…
Cancel
Save
Reference in new issue