Update packet building logic to work with header byte
This commit is contained in:
31
Hotdog.ino
31
Hotdog.ino
@@ -10,6 +10,11 @@
|
||||
#define RF_CS_PIN (15) // pins for: esp
|
||||
#define RF_IRQ_PIN (4) // run a jumper from IRQ pin to pin 2
|
||||
|
||||
RF24 radio(RF_CE_PIN, RF_CS_PIN);
|
||||
|
||||
// Copied from Powerview Hub userdata API (eg: http://POWERVIEW_HUB_IP_ADDRESS/api/userdata/ and find the field labeled "rfID")
|
||||
static const uint16_t rfID = 0x2EC8;
|
||||
|
||||
EspMQTTClient client(
|
||||
SECRET_WIFI_SSID, // Wifi SSID
|
||||
SECRET_WIFI_PASSWORD, // Wifi Password
|
||||
@@ -20,10 +25,6 @@ EspMQTTClient client(
|
||||
1883
|
||||
);
|
||||
|
||||
byte addr[3] = { 0xC0, 0xC8, 0x2E }; // The address was captured as "2EC8C0" and the bytes were reversed
|
||||
|
||||
RF24 radio(RF_CE_PIN, RF_CS_PIN);
|
||||
|
||||
void setup() {
|
||||
for (int i = 0; i < 32; i++) {
|
||||
buf[i] = 0x00;
|
||||
@@ -50,17 +51,21 @@ void onConnectionEstablished() {
|
||||
client.subscribe("hotdog/test_mqtt_blind/set", [] (const String &payload) {
|
||||
Serial.print("Set on test_mqtt_blind: ");
|
||||
Serial.println(payload);
|
||||
uint16_t shadeID = 0x0400;
|
||||
if (payload == "OPEN") {
|
||||
constructUpPacket();
|
||||
printBuffer();
|
||||
constructUpPacket(shadeID);
|
||||
printByteArray(buf);
|
||||
Serial.println();
|
||||
sendCommand(buf);
|
||||
} else if (payload == "CLOSE") {
|
||||
constructDownPacket();
|
||||
printBuffer();
|
||||
constructDownPacket(shadeID);
|
||||
printByteArray(buf);
|
||||
Serial.println();
|
||||
sendCommand(buf);
|
||||
} else if (payload == "STOP") {
|
||||
constructStopPacket();
|
||||
printBuffer();
|
||||
constructStopPacket(shadeID);
|
||||
printByteArray(buf);
|
||||
Serial.println();
|
||||
sendCommand(buf);
|
||||
}
|
||||
});
|
||||
@@ -91,7 +96,7 @@ void radioTransmitSetup() {
|
||||
radio.setAddressWidth(3);
|
||||
radio.setRetries(0, 0);
|
||||
|
||||
radio.openWritingPipe(addr);
|
||||
radio.openWritingPipe(rfID);
|
||||
radio.powerUp();
|
||||
//radio.printDetails();
|
||||
//radio.printPrettyDetails();
|
||||
@@ -100,12 +105,12 @@ void radioTransmitSetup() {
|
||||
|
||||
void sendCommand(byte * byteArray) //transmit a command
|
||||
{
|
||||
uint8_t bytecount = byteArray[0] + 3;
|
||||
uint8_t bytecount = byteArray[1] + 4;
|
||||
for (int j = 1; j < 5; j++) {
|
||||
radio.setAddressWidth(3);
|
||||
radio.disableCRC();
|
||||
radio.setAutoAck(false);
|
||||
radio.openWritingPipe(addr);
|
||||
radio.openWritingPipe(rfID);
|
||||
for (int i = 1; i < 200; i++) {
|
||||
radio.writeFast(byteArray, bytecount);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user