Init Shared Repo
This commit is contained in:
5
MyIRemote/.gitignore
vendored
Normal file
5
MyIRemote/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
.pio
|
||||
.vscode/.browse.c_cpp.db*
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
7
MyIRemote/.vscode/extensions.json
vendored
Normal file
7
MyIRemote/.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||
// for the documentation about the extensions.json format
|
||||
"recommendations": [
|
||||
"platformio.platformio-ide"
|
||||
]
|
||||
}
|
||||
39
MyIRemote/include/README
Normal file
39
MyIRemote/include/README
Normal file
@@ -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
|
||||
46
MyIRemote/lib/README
Normal file
46
MyIRemote/lib/README
Normal file
@@ -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
|
||||
19
MyIRemote/platformio.ini
Normal file
19
MyIRemote/platformio.ini
Normal file
@@ -0,0 +1,19 @@
|
||||
; 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:esp32doit-devkit-v1]
|
||||
platform = espressif32
|
||||
board = esp32doit-devkit-v1
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
lib_deps =
|
||||
knolleary/PubSubClient@^2.8
|
||||
crankyoldgit/IRremoteESP8266@^2.7.10
|
||||
khoih-prog/ESP_WiFiManager@^1.1.2
|
||||
208
MyIRemote/src/IRBedroom.cpp
Normal file
208
MyIRemote/src/IRBedroom.cpp
Normal file
@@ -0,0 +1,208 @@
|
||||
#include <Arduino.h>
|
||||
#include <IRrecv.h>
|
||||
#include <IRsend.h>
|
||||
#include <IRremoteESP8266.h>
|
||||
#include <IRac.h>
|
||||
#include <IRtext.h>
|
||||
#include <IRutils.h>
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
|
||||
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
|
||||
IRsend irsend(kIrLed); // Set the GPIO to be used to sending the message.
|
||||
|
||||
// IR Receiver connected to PIN D5 (14)
|
||||
const uint16_t kRecvPin = 14;
|
||||
const uint32_t kBaudRate = 115200;
|
||||
const uint16_t kCaptureBufferSize = 1024;
|
||||
#if DECODE_AC
|
||||
// Some A/C units have gaps in their protocols of ~40ms. e.g. Kelvinator
|
||||
// A value this large may swallow repeats of some protocols
|
||||
const uint8_t kTimeout = 50;
|
||||
#else // DECODE_AC
|
||||
// Suits most messages, while not swallowing many repeats.
|
||||
const uint8_t kTimeout = 15;
|
||||
#endif // DECODE_AC
|
||||
const uint16_t kMinUnknownSize = 12;
|
||||
#define LEGACY_TIMING_INFO false
|
||||
IRrecv irrecv(kRecvPin, kCaptureBufferSize, kTimeout, true);
|
||||
decode_results results; // Somewhere to store the results
|
||||
|
||||
|
||||
// Update these with values suitable for your network.
|
||||
const char* ssid = "JoeNelsDarlings";
|
||||
const char* password = "Paris2016";
|
||||
const char* mqtt_server = "mqtt.ddns.kawomi.com";
|
||||
const String room_name = "IRBedroom";
|
||||
//const String room_name = "IRBedroom";
|
||||
|
||||
WiFiClient espClient;
|
||||
PubSubClient client(espClient);
|
||||
unsigned long lastMsg = 0;
|
||||
#define MSG_BUFFER_SIZE (50)
|
||||
char msg[MSG_BUFFER_SIZE];
|
||||
int value = 0;
|
||||
|
||||
void setup_wifi() {
|
||||
|
||||
delay(10);
|
||||
// We start by connecting to a WiFi network
|
||||
Serial.println();
|
||||
Serial.print("Connecting to ");
|
||||
Serial.println(ssid);
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(ssid, password);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
randomSeed(micros());
|
||||
|
||||
Serial.println("X");
|
||||
Serial.println("WiFi connected");
|
||||
Serial.println("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
void callback(char* topic, byte* payload, unsigned int length) {
|
||||
Serial.print("Message arrived [");
|
||||
Serial.print(topic);
|
||||
|
||||
String recBuf="";
|
||||
Serial.print("] ");
|
||||
for (int i = 0; i < length; i++) {
|
||||
recBuf += (char)payload[i];
|
||||
}
|
||||
Serial.println(recBuf);
|
||||
|
||||
int numEle=1;
|
||||
for (int i=0; i<recBuf.length() ; i++){
|
||||
if (recBuf.charAt(i) == ',') {
|
||||
numEle++;
|
||||
}
|
||||
}
|
||||
recBuf+=",";
|
||||
|
||||
Serial.print("NumEle ");
|
||||
Serial.println(numEle);
|
||||
|
||||
int rawPos=0;
|
||||
uint16_t rawData[numEle];
|
||||
String bufSingleNum="";
|
||||
for (int i=0;i<recBuf.length();i++){
|
||||
if (recBuf.charAt(i) != ',') {
|
||||
bufSingleNum+=recBuf.charAt(i);
|
||||
} else {
|
||||
bufSingleNum.trim();
|
||||
rawData[rawPos++]=bufSingleNum.toInt();
|
||||
bufSingleNum="";
|
||||
}
|
||||
}
|
||||
|
||||
irrecv.disableIRIn(); // Stop the receiver
|
||||
irsend.sendRaw(rawData, numEle, 38);
|
||||
irrecv.enableIRIn(); // Start the receiver
|
||||
}
|
||||
|
||||
void reconnect() {
|
||||
// Loop until we're reconnected
|
||||
while (!client.connected()) {
|
||||
Serial.print("Attempting MQTT connection...");
|
||||
// Create a random client ID
|
||||
String clientId = String("ESP8266" + room_name);
|
||||
//clientId += String(random(0xffff), HEX);
|
||||
// Attempt to connect
|
||||
if (client.connect(clientId.c_str())) {
|
||||
Serial.println("connected");
|
||||
// Once connected, publish an announcement...
|
||||
client.publish(room_name.c_str(), "Connected");
|
||||
// ... and resubscribe
|
||||
client.subscribe(String(room_name + "/SendIR").c_str());
|
||||
} else {
|
||||
Serial.print("failed, rc=");
|
||||
Serial.print(client.state());
|
||||
Serial.println(" try again in 5 seconds");
|
||||
// Wait 5 seconds before retrying
|
||||
delay(5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output
|
||||
Serial.begin(kBaudRate);
|
||||
setup_wifi();
|
||||
client.setBufferSize(4096);
|
||||
client.setServer(mqtt_server, 1883);
|
||||
client.setCallback(callback);
|
||||
|
||||
// OTAwifi(); // start default wifi (previously saved on the ESP) for OTA
|
||||
#if defined(ESP8266)
|
||||
Serial.begin(kBaudRate, SERIAL_8N1, SERIAL_TX_ONLY);
|
||||
#else // ESP8266
|
||||
Serial.begin(kBaudRate, SERIAL_8N1);
|
||||
#endif // ESP8266
|
||||
while (!Serial) // Wait for the serial connection to be establised.
|
||||
delay(50);
|
||||
Serial.printf("\n" D_STR_IRRECVDUMP_STARTUP "\n", kRecvPin);
|
||||
// OTAinit(); // setup OTA handlers and show IP
|
||||
#if DECODE_HASH
|
||||
// Ignore messages with less than minimum on or off pulses.
|
||||
irrecv.setUnknownThreshold(kMinUnknownSize);
|
||||
#endif // DECODE_HASH
|
||||
irrecv.enableIRIn(); // Start the receiver
|
||||
|
||||
|
||||
irsend.begin();
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
if (!client.connected()) {
|
||||
reconnect();
|
||||
}
|
||||
client.loop();
|
||||
|
||||
/* unsigned long now = millis();
|
||||
if (now - lastMsg > 2000) {
|
||||
lastMsg = now;
|
||||
++value;
|
||||
snprintf (msg, MSG_BUFFER_SIZE, "hello world #%ld", value);
|
||||
Serial.print("Publish message: ");
|
||||
Serial.println(msg);
|
||||
client.publish("IRBedroomReceivedIR", msg);
|
||||
}
|
||||
*/
|
||||
// Check if the IR code has been received.
|
||||
if (irrecv.decode(&results)) {
|
||||
// Display a crude timestamp.
|
||||
uint32_t now = millis();
|
||||
Serial.printf(D_STR_TIMESTAMP " : %06u.%03u\n", now / 1000, now % 1000);
|
||||
// Check if we got an IR message that was to big for our capture buffer.
|
||||
if (results.overflow)
|
||||
Serial.printf(D_WARN_BUFFERFULL "\n", kCaptureBufferSize);
|
||||
// Display the library version the message was captured with.
|
||||
Serial.println(D_STR_LIBRARY " : v" _IRREMOTEESP8266_VERSION_ "\n");
|
||||
// Display the basic output of what we found.
|
||||
String theResult,theSrc;
|
||||
theResult=resultToHumanReadableBasic(&results);
|
||||
theSrc=resultToSourceCode(&results);
|
||||
Serial.println(theSrc.c_str());
|
||||
|
||||
|
||||
bool isPub = client.publish(String(room_name + "/ReceivedIR").c_str(), theSrc.c_str());
|
||||
if (isPub)
|
||||
Serial.println("PUBLISHED");
|
||||
else
|
||||
Serial.println("PUBLISH FAILED");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
11
MyIRemote/test/README
Normal file
11
MyIRemote/test/README
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user