Forum: Mikrocontroller und Digitale Elektronik OpenMilight Neues Protokoll?


von Andi S. (sn0000py)


Lesenswert?

Hallo

Wollte mal fragen ob jemand Erfahrung mit dem OpenMilight hat?

Ich habe so eine Milight Remote, und mal einen Arduino Nano mit nem 
NRF24L01 zusammengehängt.
Openmilight compiliert und geflasht, und gehofft das wenn ich auf 
receive stelle ich vielleicht schon was bekomme.

Ich glaube das die originale openmilight nicht mit den neueren funkt.

Dann habe ich dieses Script gefunden, allerdings lässt es sich nicht 
kompilieren bekomme folgenden Fehler :
1
openmili:23: error: 'V2_OFFSETS' does not name a type V2_OFFSETS[byte-1][key%4] 
2
openmili.ino: In function 'void decodeV2Packet(uint8_t*)':
3
openmili:55: error: expected primary-expression before ')' token
4
5
     packet[i] = decodeByte(packet[i], 0, key, V2_OFFSET(i, packet[0], V2_OFFSET_JUMP_START));
6
7
openmili.ino: In function 'void loop()':
8
9
openmili:106: error: expected primary-expression before ')' token
10
11
         packet[i] = decodeByte(packet[i], 0, key, V2_OFFSET(i, packet[0], V2_OFFSET_JUMP_START));
12
13
exit status 1
14
'V2_OFFSETS' does not name a type

laut google sagt der Fehler aus das das V2_OFFSETS vorher deklariert 
werden müsste (was anfangs nicht war, aber leider auch nichts brachte)

Script
1
#include <SPI.h>
2
#include <nRF24L01.h>
3
#include <RF24.h> //http://tmrh20.github.io/RF24/
4
#include "PL1167_nRF24.h"
5
#include "MiLightRadio.h"
6
7
// define connection pins for nRF24L01 shield on www.arduino-projects4u.com
8
#define CE_PIN 9   //ESP8266 2
9
#define CSN_PIN 10 //ESP8266 15
10
11
uint8_t const V2_OFFSETS[][4] = {
12
  { 0x45, 0x1F, 0x14, 0x5C },
13
  { 0x2B, 0xC9, 0xE3, 0x11 },
14
  { 0xEE, 0xDE, 0x0B, 0xAA },
15
  { 0xAF, 0x03, 0x1D, 0xF3 },
16
  { 0x1A, 0xE2, 0xF0, 0xD1 },
17
  { 0x04, 0xD8, 0x71, 0x42 },
18
  { 0xAF, 0x04, 0xDD, 0x07 },
19
  { 0xE1, 0x93, 0xB8, 0xE4 }
20
};
21
22
#define V2_OFFSET(byte, key, jumpStart) ( 
23
  V2_OFFSETS[byte-1][key%4] 
24
    + 
25
  ((jumpStart > 0 && key >= jumpStart && key <= jumpStart+0x80) ? 0x80 : 0) 
26
)
27
28
#define V2_OFFSET_JUMP_START 0x54
29
30
31
uint8_t xorKey(uint8_t key) {
32
  // Generate most significant nibble
33
  const uint8_t shift = (key & 0x0F) < 0x04 ? 0 : 1;
34
  const uint8_t x = (((key & 0xF0) >> 4) + shift + 6) % 8;
35
  const uint8_t msn = (((4 + x) ^ 1) & 0x0F) << 4;
36
  // Generate least significant nibble
37
  const uint8_t lsn = ((((key & 0x0F) + 4)^2) & 0x0F);
38
  return ( msn | lsn );
39
}
40
uint8_t decodeByte(uint8_t byte, uint8_t s1, uint8_t xorKey, uint8_t s2) {
41
  uint8_t value = byte - s2;
42
  value = value ^ xorKey;
43
  value = value - s1;
44
  return value;
45
}
46
uint8_t encodeByte(uint8_t byte, uint8_t s1, uint8_t xorKey, uint8_t s2) {
47
  uint8_t value = byte + s1;
48
  value = value ^ xorKey;
49
  value = value + s2;
50
  return value;
51
}
52
void decodeV2Packet(uint8_t *packet) {
53
  uint8_t key = xorKey(packet[0]);
54
  for (size_t i = 1; i <= 8; i++) {
55
    packet[i] = decodeByte(packet[i], 0, key, V2_OFFSET(i, packet[0], V2_OFFSET_JUMP_START));
56
  }
57
}
58
RF24 radio(CE_PIN, CSN_PIN);
59
PL1167_nRF24 prf(radio);
60
MiLightRadio mlr(prf);
61
62
void setup()
63
{
64
  Serial.begin(115200);
65
  Serial.println();
66
  delay(1000);
67
  Serial.println("# OpenMiLight Receiver/Transmitter starting");
68
  mlr.begin();
69
}
70
71
72
static int dupesPrinted = 0;
73
//static bool receiving = true; //set receiving true or false
74
//static bool escaped = false;
75
//static uint8_t outgoingPacket[7];
76
//static uint8_t outgoingPacketPos = 0;
77
//static uint8_t nibble;
78
//uint8_t crc;
79
static enum {
80
  IDLE,
81
  HAVE_NIBBLE,
82
  COMPLETE,
83
} state;
84
85
void loop()
86
{
87
    if (mlr.available()) {
88
      uint8_t packet[9];
89
      size_t packet_length = sizeof(packet);
90
      Serial.println();
91
      Serial.print("<-- ");
92
      if (packet_length<0x10) Serial.print("0");
93
      Serial.print(packet_length,HEX);
94
      Serial.print(" ");     
95
      mlr.read(packet, packet_length);
96
      for (int i = 0; i < packet_length; i++) {
97
        if (packet[i]<0x10) Serial.print("0");
98
        Serial.print(packet[i],HEX);
99
        Serial.print(" ");
100
      }
101
      Serial.print("Decoded package = ");
102
      uint8_t key = xorKey(packet[0]);
103
      uint8_t sum = key;
104
      Serial.print(key,HEX);Serial.print(" ");
105
      for (size_t i = 1; i <= 7; i++) {
106
        packet[i] = decodeByte(packet[i], 0, key, V2_OFFSET(i, packet[0], V2_OFFSET_JUMP_START));
107
        sum += packet[i];
108
        if (packet[i]<0x10) {Serial.print("0");}
109
        Serial.print(packet[i],HEX);Serial.print(" ");
110
      }
111
    }
112
    int dupesReceived = mlr.dupesReceived();
113
    for (; dupesPrinted < dupesReceived; dupesPrinted++) {
114
    Serial.print(".");
115
    } 
116
}


Noch wer ideen?

von Andi S. (sn0000py)


Lesenswert?

Also compilieren lässt es sich nun (fehlende \ im define) aber 
funktionieren tut es leider nicht.

mlr.available() ist immer false ....
Remote funktioniert, da der FUT039 sich damit bedienen lässt.

Wer noch eine Idee?


... und nun läufts auch schon :D

: Bearbeitet durch User
von Ernie A. (ruron)


Lesenswert?

Hallo! Kannst Du vielleicht mal den Code posten, der bei dir jetzt 
läuft? Habe die gleiche Fehlermeldung, bekomme es aber nicht hin.

Ich habe den define in eine Zeile geschrieben, dann brauch tman keine \
1
#define V2_OFFSET(byte, key, jumpStart) ( 
2
  V2_OFFSETS[byte-1][key%4]+((jumpStart > 0 && key >= jumpStart && key <= jumpStart+0x80) ? 0x80 : 0) 
3
)

Falls es was ausmacht, ich editiere/kompiliere den Code in der Arduino 
IDE

von Ernie A. (ruron)


Lesenswert?

...indem ich den Code mal in Eclipse geladen habe, wurde ich auf die 
Tatsache aufmerksam, dass der define wirklich in einer Zeile dann auch 
tatsächlich funktioniert - in meinem Codezitat handelt es sich ja in 
Wirklichkeit um 3 Zeilen...

Damit kompiliert es dann auch in der Arduino IDE, aber beim ir steht 
dann im Serialmonitor immer nur "# OpenMiLight Receiver/Transmitter 
starting" und sonst passiert nichts.

Ich habe im Quellcode die auskommentierten Zuweisungen vor der loop() 
aktiviert und receiving=true gesetzt.

von Andi S. (sn0000py)


Lesenswert?

Also ich hab mittlerweile den Code nur mehr mit integriereten CAN ...
ich weiss nur mein problem war damals, das ich die Libraries falsche 
versionen hatte
1
#include <SPI.h>
2
#include <nRF24L01.h>
3
#include <RF24.h> //http://tmrh20.github.io/RF24/
4
#include "PL1167_nRF24.h"
5
#include "MiLightRadio.h"
6
#include <mcp_can.h>
7
#include "RGBLED.h"
8
9
// CAN TX Variables
10
unsigned long prevTX = 0;                                        // Variable to store last execution time
11
const unsigned int invlTX = 1000;                                // One second interval constant
12
byte data[] = {0x1A, 0x55, 0x01, 0x10, 0xFF, 0x12, 0x34, 0x56};  // Generic CAN data to send
13
14
// CAN RX Variables
15
long unsigned int rxId;
16
unsigned char len;
17
unsigned char rxBuf[8];
18
19
// Serial Output String Buffer
20
char msgString[128];
21
22
// CAN0 INT and CS
23
#define CAN0_INT 4                              // Set INT to pin 2
24
MCP_CAN CAN0(7);                               // Set CS to pin 10
25
26
27
28
29
// define connection pins for nRF24L01 shield on www.arduino-projects4u.com
30
#define CE_PIN 9   //ESP8266 2
31
#define CSN_PIN 10 //ESP8266 15
32
33
#define V2_OFFSET(byte, key, jumpStart) ( \
34
  V2_OFFSETS[byte-1][key%4] \
35
    + \
36
  ((jumpStart > 0 && key >= jumpStart && key <= jumpStart+0x80) ? 0x80 : 0) \
37
) 
38
int mode=1; // Transmitting mode 1 = RGBW   2 = CCT   3 = RGB + CCT   4 = RGB
39
#define V2_OFFSET_JUMP_START 0x54
40
41
uint8_t const V2_OFFSETS[][4] = {
42
  { 0x45, 0x1F, 0x14, 0x5C },
43
  { 0x2B, 0xC9, 0xE3, 0x11 },
44
  { 0xEE, 0xDE, 0x0B, 0xAA },
45
  { 0xAF, 0x03, 0x1D, 0xF3 },
46
  { 0x1A, 0xE2, 0xF0, 0xD1 },
47
  { 0x04, 0xD8, 0x71, 0x42 },
48
  { 0xAF, 0x04, 0xDD, 0x07 },
49
  { 0xE1, 0x93, 0xB8, 0xE4 }
50
};
51
uint8_t xorKey(uint8_t key) {
52
  // Generate most significant nibble
53
  const uint8_t shift = (key & 0x0F) < 0x04 ? 0 : 1;
54
  const uint8_t x = (((key & 0xF0) >> 4) + shift + 6) % 8;
55
  const uint8_t msn = (((4 + x) ^ 1) & 0x0F) << 4;
56
  // Generate least significant nibble
57
  const uint8_t lsn = ((((key & 0x0F) + 4)^2) & 0x0F);
58
  return ( msn | lsn );
59
}
60
uint8_t decodeByte(uint8_t byte, uint8_t s1, uint8_t xorKey, uint8_t s2) {
61
  uint8_t value = byte - s2;
62
  value = value ^ xorKey;
63
  value = value - s1;
64
  return value;
65
}
66
uint8_t encodeByte(uint8_t byte, uint8_t s1, uint8_t xorKey, uint8_t s2) {
67
  uint8_t value = byte + s1;
68
  value = value ^ xorKey;
69
  value = value + s2;
70
  return value;
71
}
72
void decodeV2Packet(uint8_t *packet) {
73
  uint8_t key = xorKey(packet[0]);
74
  for (size_t i = 1; i <= 8; i++) {
75
    packet[i] = decodeByte(packet[i], 0, key, V2_OFFSET(i, packet[0], V2_OFFSET_JUMP_START));
76
  }
77
}
78
RF24 radio(CE_PIN, CSN_PIN);
79
PL1167_nRF24 prf(radio);
80
MiLightRadio mlr(prf);
81
82
RGBLED rgbLed(6,3,5,COMMON_CATHODE);
83
84
void setup()
85
{
86
  Serial.begin(115200);
87
  Serial.println();
88
  delay(1000);
89
  Serial.println("# OpenMiLight Receiver/Transmitter starting v4");
90
  mlr.begin();
91
92
  if(CAN0.begin(MCP_ANY, CAN_100KBPS, MCP_8MHZ) == CAN_OK)
93
    Serial.println("MCP2515 Initialized Successfully!");
94
  else
95
    Serial.println("Error Initializing MCP2515...");
96
  
97
  // Since we do not set NORMAL mode, we are in loopback mode by default.
98
  CAN0.setMode(MCP_NORMAL);
99
100
  pinMode(CAN0_INT, INPUT);                           // Configuring pin for /INT input
101
  
102
  Serial.println("MCP2515 Library Loopback Example...");
103
/*
104
  pinMode(6, OUTPUT);
105
  pinMode(3, OUTPUT);
106
  pinMode(5, OUTPUT);
107
*/
108
}
109
110
static int dupesPrinted = 0;
111
static enum {
112
  IDLE,
113
  HAVE_NIBBLE,
114
  COMPLETE,
115
} state;
116
117
void loop()
118
{
119
  /*
120
    rgbLed.writeRGB(255,0,0);
121
    delay(1000);
122
    rgbLed.writeRGB(0,255,0);
123
    delay(1000);
124
    rgbLed.writeRGB(0,0,255);
125
    delay(1000);
126
*/
127
    if (mlr.available()) {
128
      uint8_t packet[9];
129
      size_t packet_length = sizeof(packet);
130
      Serial.println();
131
      Serial.print("<-- ");
132
      mlr.read(packet, packet_length);
133
      if (packet_length<0x10) Serial.print("0");
134
      Serial.print(packet_length,HEX);
135
      Serial.print(" ");     
136
      for (int i = 0; i < packet_length; i++) {
137
        if (packet[i]<0x10) Serial.print("0");
138
        Serial.print(packet[i],HEX);
139
        Serial.print(" ");
140
      }
141
      if (packet_length!=7){
142
      Serial.print("Decoded package = ");
143
      uint8_t key = xorKey(packet[0]);
144
      uint8_t sum = key;
145
      Serial.print(key,HEX); Serial.print(" ");
146
      for (size_t i = 1; i <= 7; i++) {
147
        packet[i] = decodeByte(packet[i], 0, key, V2_OFFSET(i, packet[0], V2_OFFSET_JUMP_START));
148
        sum += packet[i];
149
        if (packet[i]<0x10) {Serial.print("0");}
150
        Serial.print(packet[i],HEX);Serial.print(" ");
151
      }
152
153
      // ColorWheel
154
      if (packet[4] == 0x02) {
155
        
156
        uint32_t val = packet[5];
157
        if (val < 0) val = val + 256;
158
        Serial.print("HSV : ");
159
        val = (val * (uint32_t)360);// / (uint16_t)255;
160
        Serial.print(val);    Serial.print("; ");
161
        val = val >> 8;
162
        val = (val - 70+360-24) % 360;
163
        rgbLed.writeHSV(val, 1, 1);
164
        Serial.print("HSV : ");
165
        Serial.print(packet[5]);
166
        Serial.print(" -> ");
167
        Serial.print(val);
168
      }
169
    }
170
    }
171
    int dupesReceived = mlr.dupesReceived();
172
    for (; dupesPrinted < dupesReceived; dupesPrinted++) {
173
    Serial.print(".");
174
    } 
175
176
177
    if(!digitalRead(CAN0_INT))                          // If CAN0_INT pin is low, read receive buffer
178
  {
179
    CAN0.readMsgBuf(&rxId, &len, rxBuf);              // Read data: len = data length, buf = data byte(s)
180
    
181
    if((rxId & 0x80000000) == 0x80000000)             // Determine if ID is standard (11 bits) or extended (29 bits)
182
      sprintf(msgString, "Extended ID: 0x%.8lX  DLC: %1d  Data:", (rxId & 0x1FFFFFFF), len);
183
    else
184
      sprintf(msgString, "Standard ID: 0x%.3lX       DLC: %1d  Data:", rxId, len);
185
  
186
    Serial.print(msgString);
187
  
188
    if((rxId & 0x40000000) == 0x40000000){            // Determine if message is a remote request frame.
189
      sprintf(msgString, " REMOTE REQUEST FRAME");
190
      Serial.print(msgString);
191
    } else {
192
      for(byte i = 0; i<len; i++){
193
        sprintf(msgString, " 0x%.2X", rxBuf[i]);
194
        Serial.print(msgString);
195
      }
196
    }
197
        
198
    Serial.println();
199
  }
200
  /*
201
  if(millis() - prevTX >= invlTX){                    // Send this at a one second interval. 
202
    prevTX = millis();
203
    byte sndStat = CAN0.sendMsgBuf(0x100, 7, data);
204
    
205
    if(sndStat == CAN_OK)
206
      Serial.println("Message Sent Successfully!");
207
    else {
208
      sprintf(msgString, "Error Sending Message... %d", sndStat);
209
      Serial.println(msgString);
210
    }
211
212
  }*/
213
}

versuche den code mal die can sachen einfach rauslöschen, wenns nicht 
funktioniert, dann schau das du bei den library sachen die korrekten 
drauf hast ... und wenn das auch nicht funktioniert, dann kann ich dir 
meine libraries die hier funktioniert haben irgendwo raufkopieren.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.