5 changed files with 117 additions and 0 deletions
@ -0,0 +1,5 @@ |
|||
.pio |
|||
.vscode/.browse.c_cpp.db* |
|||
.vscode/c_cpp_properties.json |
|||
.vscode/launch.json |
|||
.vscode/ipch |
@ -0,0 +1,10 @@ |
|||
{ |
|||
// See http://go.microsoft.com/fwlink/?LinkId=827846 |
|||
// for the documentation about the extensions.json format |
|||
"recommendations": [ |
|||
"platformio.platformio-ide" |
|||
], |
|||
"unwantedRecommendations": [ |
|||
"ms-vscode.cpptools-extension-pack" |
|||
] |
|||
} |
@ -0,0 +1,15 @@ |
|||
; 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 |
|||
monitor_speed = 115200 |
@ -0,0 +1,76 @@ |
|||
#include <Arduino.h> |
|||
#include <WiFi.h> |
|||
#include <HTTPClient.h> |
|||
|
|||
const char* ssid = "tksteti"; |
|||
const char* password = "ProsimTeNevim"; |
|||
|
|||
const char* serverName = "api.thingspeak.com"; |
|||
const String apiKey = "DJFN3ZJGKAO5BXMJ"; |
|||
|
|||
const int ledPin = 2; |
|||
|
|||
const char* hostname = "ESP-Thingspeak-Skrabanek"; |
|||
|
|||
//přidat deklaraci kvuli C++ pro zajištění "existence" nové metody
|
|||
void sendData2ThingSpeak(int value); |
|||
|
|||
void setup() { |
|||
Serial.begin(115200); |
|||
pinMode(ledPin, OUTPUT); |
|||
|
|||
WiFi.hostname(hostname); |
|||
|
|||
WiFi.begin(ssid,password); |
|||
while (WiFi.status() != WL_CONNECTED) |
|||
{ |
|||
Serial.print("."); |
|||
delay(400); |
|||
} |
|||
Serial.println("\nWiFi připojena"); |
|||
Serial.print("IP adresa: "); |
|||
Serial.println(WiFi.localIP()); |
|||
Serial.print("hostname:"); |
|||
Serial.println(WiFi.getHostname()); |
|||
|
|||
} |
|||
|
|||
void loop() { |
|||
int randomValue = random(0,101); |
|||
Serial.print("Nahodne cislo: "); |
|||
Serial.println(randomValue); |
|||
|
|||
digitalWrite(ledPin, HIGH); |
|||
sendData2ThingSpeak(randomValue); |
|||
digitalWrite(ledPin,LOW); |
|||
|
|||
delay(5000); |
|||
} |
|||
|
|||
void sendData2ThingSpeak(int value) { |
|||
if (WiFi.status() == WL_CONNECTED) { |
|||
Serial.println("WiFi připojeno"); |
|||
HTTPClient http; |
|||
String url = "http://"; |
|||
url += serverName; |
|||
url += "/update?api_key="; |
|||
url += apiKey; |
|||
url += "&field1="; //AltGR+C=&
|
|||
url += value; |
|||
Serial.println(url); |
|||
http.begin(url); |
|||
int httpResponseCode = http.GET(); |
|||
if (httpResponseCode > 0) { |
|||
Serial.print("HTTP Response code:"); |
|||
Serial.println(httpResponseCode); |
|||
//vypsat odpověd
|
|||
String payload = http.getString(); |
|||
Serial.println(payload); |
|||
} else { |
|||
Serial.print("Error code: "); |
|||
Serial.println(httpResponseCode); |
|||
} |
|||
} else { |
|||
Serial.println("WiFi odpojeno"); |
|||
} |
|||
} |
@ -0,0 +1,11 @@ |
|||
|
|||
This directory is intended for PlatformIO Test Runner 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/en/latest/advanced/unit-testing/index.html |
Loading…
Reference in new issue