just some reformatting - no code changes

This commit is contained in:
Joe Tretter
2022-07-05 14:18:19 -05:00
parent 58ab37520a
commit 4e2b454ac5

View File

@@ -1,15 +1,13 @@
#include <Arduino.h>
#include <IRrecv.h>
#include <IRsend.h>
#include <IRremoteESP8266.h>
#include <ESP8266WiFi.h>
#include <IRac.h>
#include <IRrecv.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <IRtext.h>
#include <IRutils.h>
#include <ESP8266WiFi.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.
@@ -30,12 +28,11 @@ const uint16_t kMinUnknownSize = 12;
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 = "JoNelsDarlings";
const char* password = "Paris2016";
const char* mqtt_server = "mqtt.ddns.kawomi.com";
//const String room_name = "IRLivingroom";
const char *ssid = "JoNelsDarlings";
const char *password = "Paris2016";
const char *mqtt_server = "mqtt.ddns.kawomi.com";
// const String room_name = "IRLivingroom";
const String room_name = "IRBedroom";
WiFiClient espClient;
@@ -46,7 +43,6 @@ char msg[MSG_BUFFER_SIZE];
int value = 0;
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
@@ -69,38 +65,38 @@ void setup_wifi() {
Serial.println(WiFi.localIP());
}
void callback(char* topic, byte* payload, unsigned int length) {
void callback(char *topic, byte *payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
String recBuf="";
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++){
int numEle = 1;
for (int i = 0; i < recBuf.length(); i++) {
if (recBuf.charAt(i) == ',') {
numEle++;
}
}
recBuf+=",";
recBuf += ",";
Serial.print("NumEle ");
Serial.println(numEle);
int rawPos=0;
int rawPos = 0;
uint16_t rawData[numEle];
String bufSingleNum="";
for (int i=0;i<recBuf.length();i++){
String bufSingleNum = "";
for (int i = 0; i < recBuf.length(); i++) {
if (recBuf.charAt(i) != ',') {
bufSingleNum+=recBuf.charAt(i);
bufSingleNum += recBuf.charAt(i);
} else {
bufSingleNum.trim();
rawData[rawPos++]=bufSingleNum.toInt();
bufSingleNum="";
rawData[rawPos++] = bufSingleNum.toInt();
bufSingleNum = "";
}
}
@@ -115,7 +111,7 @@ void reconnect() {
Serial.print("Attempting MQTT connection...");
// Create a random client ID
String clientId = String("ESP8266" + room_name);
//clientId += String(random(0xffff), HEX);
// clientId += String(random(0xffff), HEX);
// Attempt to connect
if (client.connect(clientId.c_str())) {
Serial.println("connected");
@@ -157,19 +153,16 @@ void setup() {
#endif // DECODE_HASH
irrecv.enableIRIn(); // Start the receiver
irsend.begin();
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
/* unsigned long now = millis();
/* unsigned long now = millis();
if (now - lastMsg > 2000) {
lastMsg = now;
++value;
@@ -178,7 +171,7 @@ void loop() {
Serial.println(msg);
client.publish("IRBedroomReceivedIR", msg);
}
*/
*/
// Check if the IR code has been received.
if (irrecv.decode(&results)) {
// Display a crude timestamp.
@@ -190,19 +183,16 @@ void loop() {
// 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);
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());
bool isPub = client.publish(String(room_name + "/ReceivedIR").c_str(),
theSrc.c_str());
if (isPub)
Serial.println("PUBLISHED");
else
Serial.println("PUBLISH FAILED");
}
}