- Location:
- /trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
/trunk/L_EnOceanESP3.lua
r1 r3 7 7 ------------------------------------------------------------------------------- 8 8 9 local DEBUG_MODE = true 10 9 local DEBUG_MODE = true 10 local WAIT_FOR_RESPONSE = false -- If this is 'true', no further messages will be sent 11 local SENDING_IN_PROGRESS = false 11 12 12 13 ------------------------------------------------------------------------------- … … 15 16 16 17 -- Services 17 local ENOCEAN_SID = "urn:enocean-com:serviceId:EnoceanGatewayESP3" 18 local SES_SID = "urn:micasaverde-com:serviceId:SecuritySensor1" 18 local SID = { 19 ENOCEAN = "urn:micasaverde-com:serviceId:EnoceanGatewayESP3", 20 SES = "urn:micasaverde-com:serviceId:SecuritySensor1" 21 } 19 22 20 23 -- Message types 21 local TASK= {24 local SYS_MESSAGE_TYPES = { 22 25 BUSY = 1, 23 26 ERROR = 2, … … 25 28 } 26 29 27 ------------------------------------------------------------------------------- 30 -- Delays for luup.delay, in seconds 31 local DELAYS = { 32 PROCESS_PACKET = 1, 33 SEND_NEXT_MESSAGE = 2 34 } 35 36 ------------------------------------------------------------------------------- 37 38 local SYNC_BYTE = string.char(0x55) 28 39 29 40 local STATE = { 30 ["GET_SYNC_STATE"] = 0, 31 ["GET_HEADER_STATE"] = 1, 32 ["CHECK_CRC8H_STATE"] = 2, 33 ["GET_DATA_STATE"] = 3, 34 ["CHECK_CRC8D_STATE"] = 4 35 } 36 37 local SYNC_BYTE = string.char(0x55) 41 GET_SYNC_STATE = 0, 42 GET_HEADER_STATE = 1, 43 CHECK_CRC8H_STATE = 2, 44 GET_DATA_STATE = 3, 45 CHECK_CRC8D_STATE = 4 46 } 47 48 local PACKET_TYPES = { 49 RADIO = string.char(0x1), 50 RESPONSE = string.char(0x2), 51 EVENT = string.char(0x4), 52 COMMON_COMMAND = string.char(0x5) 53 } 54 55 local TELEGRAM_TYPES = { 56 ["RPS"] = string.char(0xF6), 57 ["1BS"] = string.char(0xD5), 58 ["4BS"] = string.char(0xA5) 59 } 38 60 39 61 local CRC8_TABLE = { … … 80 102 81 103 local g_taskHandle = -1 82 local g_lastTask = 0 -- Timestamp of the last status message. 83 84 local g_partitions = {} 85 local g_zones = {} 86 87 local messageQueue = {} 88 local sendAttempt = 0 104 local g_lastSysMessage = 0 -- Timestamp of the last status message. 105 106 local g_messageQueue = {} 89 107 90 108 … … 95 113 local log = luup.log 96 114 local getinfo = debug.getinfo -- Get the 'getinfo' function from the 'debug' module before overwriting the 'debug' keyword. 97 98 local function debug (text) 99 if (DEBUG_MODE == true) then 100 log(text) 115 local function debug() end 116 117 118 local function showSysMessage (message, mode, critical) 119 log("(EnOceanPlugin::showSysMessage/"..(getinfo(2).name or "N/A")..") message='".. message .."', mode=".. mode ..", critical=".. critical) 120 121 luup.task(text, mode, "EnOcean Plugin", g_taskHandle) 122 g_lastSysMessage = tostring(os.time()) 123 124 if (not critical) then 125 luup.call_delay("clearSysMessage", 30, g_lastSysMessage) -- Clear the previous system message, since it's transient. 126 else 127 luup.set_failure(true, lug_device) 128 end 129 end 130 131 132 function clearSysMessage (messageTime) 133 -- 'messageTime' is nil if the function is called by the user. 134 if (messageTime == g_lastSysMessage or messageTime == nil) then 135 luup.task("Clearing...", SYS_MESSAGE_TYPES.SUCCESS, "EnOcean Plugin", g_taskHandle) 101 136 end 102 137 end 103 138 104 139 --[[ 105 local function task (text, mode)106 107 local messageType108 if (mode == TASK_ERROR or mode == TASK_ERROR_PERM) then109 messageType = "ERROR"110 else111 messageType = "STATUS"112 end113 debug("(EnOceanPlugin::task/"..(getinfo(2).name or "N/A")..") "..messageType..": "..text)114 115 g_lastTask = os.time()116 117 if (mode == TASK_ERROR_PERM) then118 luup.task(text, TASK_ERROR, "Concord Plugin", g_taskHandle)119 elseif (mode == TASK_BUSY_PERM) then120 luup.task(text, TASK_BUSY, "Concord Plugin", g_taskHandle)121 else122 luup.task(text, mode, "Concord Plugin", g_taskHandle)123 luup.call_delay("clearTask", 30, tostring(g_lastTask)) -- Clear the previous message, since it's transient.124 end125 end126 127 128 function clearTask (taskTime)129 if (taskTime ~= nil and tostring(g_lastTask) ~= taskTime) then130 return131 end132 luup.task("Clearing...", TASK_SUCCESS, "Concord Plugin", g_taskHandle)133 end134 135 136 140 local function padLeft (s, length, c) 137 141 s = tostring(s) … … 172 176 ------------------------------------------------------------------------------- 173 177 174 local function computeCrc (data, dataLen) 178 local function computeCrc (data, start, length) 179 start = start or 1 180 length = length or #data 181 175 182 local crc = 0 176 for i = 1, dataLendo183 for i = start, start + length - 1 do 177 184 crc = CRC8_TABLE[bit.bxor(crc, string.byte(data[i])) + 1] 178 185 end 179 log("(EnOceanPlugin::computeCrc) crc=".. crc) 180 return crc 181 end 182 183 184 --[[ 185 local function addToQueue(s) 186 local length = padLeft(#s / 2 + 1) 187 s = CHAR_LF .. length .. s .. string.format("%02X", checksum(length .. s)) 188 table.insert(messageQueue, s) 189 if (#messageQueue == 1) then -- This is the only message in the queue. Start the 'send' chain. 190 sendMessage() 191 end 192 end 193 194 195 function sendMessage() 196 if (#messageQueue > 0) then 197 s = messageQueue[1] 186 debug("(EnOceanPlugin::computeCrc) crc=".. crc) 187 return string.char(crc) 188 end 189 190 191 local function addToSendQueue (packetType, data, optData, waitForResponse) 192 local insert = table.insert 193 local char = string.char 194 195 local packet = { SYNC_BYTE } -- The sync byte 196 197 insert(packet, char(#data / 0x100)) -- First byte of the data length 198 insert(packet, char(#data % 0x100)) -- Seconds byte of the data length 199 insert(packet, char(#optData)) -- Length of the optional data 200 insert(packet, packetType) -- The packet type 201 insert(packet, computeCrc(packet, 2, 4)) -- The header CRC8 202 203 insert(packet, data) -- The user data 204 insert(packet, optData) -- The optional user data 205 insert(packet, computeCrc(packet, 7, #data + #optData)) -- The data CRC8 206 207 table.insert(g_messageQueue, {content = table.concat(packet), waitForResponse = (waitForResponse or false)}) 208 if (not SENDING_IN_PROGRESS) then 209 sendPacket() 210 end 211 end 212 213 214 function sendPacket() 215 SENDING_IN_PROGRESS = true 216 217 if (WAIT_FOR_RESPONSE == true) then 218 g_triesCount = g_triesCount + 1 219 if(g_triesCount < 3) then 220 debug("(EnOceanPlugin::sendPacket) WAIT_FOR_RESPONSE flag is set, g_triesCount=".. g_triesCount .."; try again in ".. DELAYS.SEND_NEXT_MESSAGE .." seconds.") 221 luup.call_delay("sendPacket", DELAYS.SEND_NEXT_MESSAGE) 222 return 223 else 224 log("(EnOceanPlugin::sendPacket) Didn't receive response for the last message. Stop waiting for response.") 225 WAIT_FOR_RESPONSE = false 226 g_triesCount = 0 227 end 228 end 229 230 local message 231 if (#g_messageQueue > 0) then 232 message = g_messageQueue[1] 198 233 else 199 234 return 200 235 end 201 236 202 sendAttempt = sendAttempt + 1 203 if (sendAttempt == 3) then 204 -- Send CR/LF to reset the automation module's message queue. 205 if (not luup.io.write(CHAR_CR .. s)) then 206 task("Failed to send message", TASK_ERROR_PERM) 207 return 208 end 209 -- Remove the message from the queue, because there's a chance that the message is wrong. 210 sendAttempt = 0 211 table.remove(messageQueue, 1) 212 elseif (not luup.io.write(s)) then 213 -- Send the message normally. 214 task("Failed to send message", TASK_ERROR_PERM) 237 debug("(EnOceanPlugin::sendPacket) Wait for response: ".. message.waitForResponse) 238 239 if (not luup.io.write(message.content)) then 240 showSysMessage("Failed to send message", SYS_MESSAGE_TYPES.ERROR) 241 luup.variable_set(SID.ENOCEAN, "CommFailure", "1", lug_device) 215 242 return 216 243 end 217 244 245 WAIT_FOR_RESPONSE = message.waitForResponse 246 table.remove(g_messageQueue, 1) 247 218 248 -- Send the next message in the queue. 219 if (#messageQueue > 0) then 220 luup.call_delay("sendMessage", SEND_DELAY) 221 end 222 end 223 224 225 local function sendChar (c) 226 if (not luup.io.write(c)) then 227 task("Failed to send message", TASK_ERROR_PERM) 228 end 229 end 230 231 232 local function decodeName (s) 233 if (s == nil or s == "") then 234 return "N/A" 235 end 236 237 s = s:gsub("(%x%x)", TOKENS) 238 239 -- Trim leading and trailing whitespace. 240 return s:match("^%s*(.-)%s*$") 241 end 242 243 244 -- Expands a number, e.g. 21 -> 0201 245 local function expand (nr) 246 if (nr == nil) then 247 return "" 248 end 249 250 local expNr = "" 251 for i = 1, #nr do 252 local d = nr:sub(i, i) 253 expNr = expNr .. padLeft(d) 254 end 255 256 return expNr 257 end 258 ]] 259 260 ------------------------------------------------------------------------------- 261 -- Message handler functions 262 ------------------------------------------------------------------------------- 249 if (#g_messageQueue > 0) then 250 luup.call_delay("sendPacket", DELAYS.SEND_NEXT_MESSAGE) 251 else 252 SENDING_IN_PROGRESS = false 253 end 254 end 255 256 257 ------------------------------------------------------------------------------- 258 -- Radio telegram handlers 259 ------------------------------------------------------------------------------- 260 261 local RADIO_TELEGRAM_HANDLERS = { 262 -- RPS 263 [TELEGRAM_TYPES.RPS] = function (data) 264 debug("(EnOceanPlugin::RPS) RPS telegram handler") 265 end, 266 267 -- 1BS 268 [TELEGRAM_TYPES["1BS"]] = function (data) 269 debug("(EnOceanPlugin::1BS) 1BS telegram handler") 270 271 end, 272 273 -- 4BS 274 [TELEGRAM_TYPES.4BS] = function (data) 275 debug("(EnOceanPlugin::4BS) 4BS telegram handler") 276 end 277 } 278 279 280 ------------------------------------------------------------------------------- 281 -- Packet handler functions 282 ------------------------------------------------------------------------------- 283 284 function handleRadioTelegram (data) 285 debug("(EnOceanPlugin::handleRadioTelegram) Handle radio telegram") 286 RADIO_TELEGRAM_HANDLERS[string.byte(data:sub(1, 1))](data:sub(2)) 287 end 288 289 290 function handleResponse (data) 291 debug("(EnOceanPlugin::handleResponse) Handle response") 292 end 293 294 295 local PACKET_HANDLERS = { 296 [PACKET_TYPES.RADIO] = "handleRadioTelegram", 297 [PACKET_TYPES.RESPONSE] = "handleResponse" 298 } 263 299 264 300 … … 267 303 ------------------------------------------------------------------------------- 268 304 269 -- 0x55 0x0 0xa 0x7 0x1 0xeb 0xa5 0xce 0x79 0x0 0xf 0x0 0x81 0x1 0x75 0x0 0x1 0xff 0xff 0xff 0xff 0x44 0x0 0x6e 305 -- 4BS 306 -- 0x55 | 0x0 0xa 0x7 0x1 | 0xeb | 0xa5 - 0xce 0x79 0x0 0xf - 0x0 0x81 0x1 0x75 - 0x0 | 0x1 0xff 0xff 0xff 0xff 0x44 0x0 | 0x6e 307 -- 0x55 | 0x0 0xa 0x7 0x1 | 0xeb | 0xa5 - 0xc6 0x79 0x0 0xf - 0x0 0x81 0x1 0x75 - 0x0 | 0x1 0xff 0xff 0xff 0xff 0x43 0x0 | 0x15 308 -- 0x55 | 0x0 0xa 0x7 0x1 | 0xeb | 0xa5 - 0xc6 0x79 0x0 0xf - 0x0 0x81 0x1 0x75 - 0x0 | 0x1 0xff 0xff 0xff 0xff 0x43 0x0 | 0x15 309 310 -- 1BS 311 -- 0x55 | 0x0 0x7 0x7 0x1 | 0x7a | 0xd5 - 0x8 - 0x0 0x1 0x8a 0xbb - 0x0 | 0x1 0xff 0xff 0xff 0xff 0x3a 0x0 | 0xbc 312 -- 0x55 | 0x0 0x7 0x7 0x1 | 0x7a | 0xd5 - 0x8 - 0x0 0x0 0x85 0xe - 0x0 | 0x1 0xff 0xff 0xff 0xff 0x37 0x0 | 0x3a 313 270 314 271 315 local state = STATE.GET_SYNC_STATE -- The current state … … 274 318 local rxDataLen = 0 -- The length of the data field 275 319 local rxOptDataLen = 0 -- The length of the optional data field 320 local rxPacketType = 0 -- The packet type 276 321 277 322 -- State machine to load incoming packet bytes … … 279 324 280 325 -- Waiting for packet sync byte 0x55 281 [STATE.GET_SYNC_STATE] = function ( byte)282 if ( byte == SYNC_BYTE) then283 log("(EnOceanPlugin::GET_SYNC_STATE) Got sync byte, go to GET_HEADER_STATE")326 [STATE.GET_SYNC_STATE] = function (rxByte) 327 if (rxByte == SYNC_BYTE) then 328 debug("(EnOceanPlugin::GET_SYNC_STATE) Got sync byte, go to GET_HEADER_STATE") 284 329 state = STATE.GET_HEADER_STATE 285 330 crc = 0 … … 289 334 290 335 -- Read the header bytes. 291 [STATE.GET_HEADER_STATE] = function ( byte)336 [STATE.GET_HEADER_STATE] = function (rxByte) 292 337 -- Add the received byte in the buffer. 293 338 rxCount = rxCount + 1 294 rxBuf[rxCount] = byte339 rxBuf[rxCount] = rxByte 295 340 -- All the header bytes received? 296 341 if(rxCount == 4) then 297 log("(EnOceanPlugin::GET_HEADER_STATE) Received all header bytes, go to CHECK_CRC8H_STATE")342 debug("(EnOceanPlugin::GET_HEADER_STATE) Received all header bytes, go to CHECK_CRC8H_STATE") 298 343 state = STATE.CHECK_CRC8H_STATE 299 344 end … … 301 346 302 347 -- Check the header checksum & try to resynchronize if and error occured. 303 [STATE.CHECK_CRC8H_STATE] = function ( byte)348 [STATE.CHECK_CRC8H_STATE] = function (rxByte) 304 349 -- Header CRC correct? 305 if (computeCrc(rxBuf, rxCount) ~= string.byte(byte)) then306 log("(EnOceanPlugin::CHECK_CRC8H_STATE) Incorrect header crc")350 if (computeCrc(rxBuf, 1, rxCount) ~= rxByte) then 351 debug("(EnOceanPlugin::CHECK_CRC8H_STATE) Incorrect header crc") 307 352 -- No. Check if there is a sync byte (0x55) in the header. 308 353 local pos = -1 … … 315 360 end 316 361 317 if (pos == -1 and byte ~= SYNC_BYTE) then362 if (pos == -1 and rxByte ~= SYNC_BYTE) then 318 363 -- Neither the header nor the CRC8H contain the sync byte 319 log("(EnOceanPlugin::CHECK_CRC8H_STATE) Neither the header nor the CRC8H contain the sync byte, go to GET_SYNC_STATE")364 debug("(EnOceanPlugin::CHECK_CRC8H_STATE) Neither the header nor the CRC8H contain the sync byte, go to GET_SYNC_STATE") 320 365 state = STATE.GET_SYNC_STATE 321 366 return 322 elseif (pos == -1 and byte == SYNC_BYTE) then367 elseif (pos == -1 and rxByte == SYNC_BYTE) then 323 368 -- The header does not contain the sync byte but the CRC8H does 324 369 -- The sync byte could be the beginning of a packet 325 log("(EnOceanPlugin::CHECK_CRC8H_STATE) The header does not contain the sync byte but the CRC8H does, go to GET_HEADER_STATE")370 debug("(EnOceanPlugin::CHECK_CRC8H_STATE) The header does not contain the sync byte but the CRC8H does, go to GET_HEADER_STATE") 326 371 state = STATE.GET_HEADER_STATE 327 372 rxCount = 0 … … 339 384 -- Copy the received byte to buffer 340 385 rxCount = rxCount + 1 341 rxBuf[rxCount] = byte386 rxBuf[rxCount] = rxByte 342 387 343 388 if (rxCount < 4) then 344 log("(EnOceanPlugin::CHECK_CRC8H_STATE) There are still header bytes to receive, go to GET_HEADER_STATE")389 debug("(EnOceanPlugin::CHECK_CRC8H_STATE) There are still header bytes to receive, go to GET_HEADER_STATE") 345 390 state = STATE.GET_HEADER_STATE 346 391 end 347 392 348 log("(EnOceanPlugin::CHECK_CRC8H_STATE) All header bytes received, stay in CHECK_CRC8H_STATE")393 debug("(EnOceanPlugin::CHECK_CRC8H_STATE) All header bytes received, stay in CHECK_CRC8H_STATE") 349 394 return 350 395 end … … 353 398 rxDataLen = string.byte(rxBuf[1]) * 256 + string.byte(rxBuf[2]) 354 399 rxOptDataLen = string.byte(rxBuf[3]) 355 log("(EnOceanPlugin::CHECK_CRC8H_STATE) Header crc correct, rxDataLen=".. rxDataLen ..", rxOptDataLen=".. rxOptDataLen)400 debug("(EnOceanPlugin::CHECK_CRC8H_STATE) Header crc correct, rxDataLen=".. rxDataLen ..", rxOptDataLen=".. rxOptDataLen) 356 401 if ((rxDataLen + rxOptDataLen) == 0) then 357 402 -- No. Sync byte received? 358 if ( byte == SYNC_BYTE) then403 if (rxByte == SYNC_BYTE) then 359 404 -- Yes 360 log("(EnOceanPlugin::CHECK_CRC8H_STATE) Header crc incorrect, sync byte not received, go to GET_HEADER_STATE")405 debug("(EnOceanPlugin::CHECK_CRC8H_STATE) Header crc incorrect, sync byte not received, go to GET_HEADER_STATE") 361 406 state = STATE.GET_HEADER_STATE 362 407 rxCount = 0 … … 365 410 366 411 -- Packet with correct CRC8H, but wrong length fields 367 log("(EnOceanPlugin::CHECK_CRC8H_STATE) Packet with correct CRC8H, but wrong length fields, go to GET_SYNC_STATE")412 debug("(EnOceanPlugin::CHECK_CRC8H_STATE) Packet with correct CRC8H, but wrong length fields, go to GET_SYNC_STATE") 368 413 state = STATE.GET_SYNC_STATE 369 log("(EnOceanPlugin::CHECK_CRC8H_STATE) Error: invalid packet")414 debug("(EnOceanPlugin::CHECK_CRC8H_STATE) Error: invalid packet") 370 415 return 371 416 end 372 417 373 418 -- Correct header CRC8. Go to the reception of data. 374 log("(EnOceanPlugin::CHECK_CRC8H_STATE) Correct header CRC8, go to GET_DATA_STATE")419 debug("(EnOceanPlugin::CHECK_CRC8H_STATE) Correct header CRC8, go to GET_DATA_STATE") 375 420 state = STATE.GET_DATA_STATE 376 421 rxCount = 0 422 rxPacketType = string.byte(rxBuf[4]) 377 423 end, 378 424 379 425 -- Copy the information bytes. 380 [STATE.GET_DATA_STATE] = function ( byte)426 [STATE.GET_DATA_STATE] = function (rxByte) 381 427 rxCount = rxCount + 1 382 rxBuf[rxCount] = byte428 rxBuf[rxCount] = rxByte 383 429 384 430 -- When all the expected bytes are received, go to calculate data checksum. 385 431 if (rxCount == (rxDataLen + rxOptDataLen)) then 386 log("(EnOceanPlugin::GET_DATA_STATE) All expected bytes received, go to CHECK_CRC8D_STATE")432 debug("(EnOceanPlugin::GET_DATA_STATE) All expected bytes received, go to CHECK_CRC8D_STATE") 387 433 state = STATE.CHECK_CRC8D_STATE 388 434 end … … 390 436 391 437 -- Check the data CRC8 392 [STATE.CHECK_CRC8D_STATE] = function ( byte)438 [STATE.CHECK_CRC8D_STATE] = function (rxByte) 393 439 -- In all cases the state returns to the first state: waiting for next sync byte. 394 440 state = STATE.GET_SYNC_STATE 395 441 396 if (computeCrc(rxBuf, rxCount) == string.byte(byte)) then442 if (computeCrc(rxBuf, 1, rxCount) == rxByte) then 397 443 -- Correct packet received 398 log("(EnOceanPlugin::CHECK_CRC8D_STATE) Correct packet received, go to GET_SYNC_STATE") 399 -- TODO: DO SOMETHING WITH THE DATA (use luup.call_delay) 444 debug("(EnOceanPlugin::CHECK_CRC8D_STATE) Correct packet received, schedule the packet handler function and go to GET_SYNC_STATE") 445 if (PACKET_HANDLERS[rxPacketType] ~= nil) then 446 luup.call_delay(PACKET_HANDLERS[rxPacketType], DELAYS.PROCESS_PACKET, table.concat(rxBuf, "", 1, rxCount)) 447 else 448 debug("(EnOceanPlugin::CHECK_CRC8D_STATE) Unhandled packet type ".. rxPacketType) 449 end 400 450 return 401 451 end … … 403 453 -- Incorrect CRC8 404 454 -- If the received byte is the sync byte, then it could be the sync byte for next packet. 405 if ( byte == SYNC_BYTE) then406 log("(EnOceanPlugin::CHECK_CRC8D_STATE) Incorrect CRC8, the received byte is the sync byte, go to GET_HEADER_STATE")455 if (rxByte == SYNC_BYTE) then 456 debug("(EnOceanPlugin::CHECK_CRC8D_STATE) Incorrect CRC8, the received byte is the sync byte, go to GET_HEADER_STATE") 407 457 state = STATE.GET_HEADER_STATE 408 458 rxCount = 0 … … 416 466 417 467 function handleIncoming (lul_data) 418 log("state=".. state ..", byte=".. (string.byte(lul_data) or "nil"))468 log("state=".. state ..", rxByte=".. (string.byte(lul_data) or "nil")) 419 469 if (STATE_MACHINE[state] ~= nil) then 420 470 STATE_MACHINE[state](lul_data) … … 430 480 ------------------------------------------------------------------------------- 431 481 482 function setTarget (device, newTargetValue) 483 --local 484 end 485 486 432 487 ----------------------------------------------------------------------------- 433 488 -- Init … … 437 492 log("(EnOceanPlugin::init) EnOcean ESP3 Gateway plugin") 438 493 494 -- Get the root device. 439 495 lug_device = lul_device 440 496 497 -- Get a handle for system messages. 441 498 g_taskHandle = luup.task("Starting up...", 1, "EnOcean plugin", -1) 442 499 443 --[[ 444 -- Check if Debug Mode is enabled. 500 -- Reset our CommFailure variable. 501 luup.variable_set(SID.ENOCEAN, "CommFailure", "0", lul_device) 502 503 -- Update the Debug Mode. 445 504 local debugMode = luup.variable_get(ENOCEAN_SID, "DebugMode", lul_device) or "" 446 505 if (debugMode == "") then 447 debugMode = DEBUG_MODE and "1" or "0" 448 luup.variable_set(ENOCEAN_SID, "DebugMode", debugMode, lul_device) 506 luup.variable_set(ENOCEAN_SID, "DebugMode", (DEBUG_MODE and "1" or "0"), lul_device) 449 507 else 450 508 DEBUG_MODE = (debugMode == "1") and true or false 451 509 end 452 510 453 -- Check if the panel is connected through the serial port, or via Ethernet. 454 local attr_ip = luup.devices[lul_device].ip or "" 455 if (attr_ip == "") then 456 debug ("(EnOceanPlugin::init) Running on Serial.") 457 else 458 local ip, port = attr_ip:match("^([%d.]+):?(%d*)$") 459 debug("(EnOceanPlugin::init) ip = '".. (ip or "nil") .."', port = '".. (port or "nil") .."'.") 460 461 -- Validate the IP. 462 if (ip:match("^%d+%.%d+%.%d+%.%d+$") ~= nil) then 463 if (port == nil or port == "") then 464 port = 5000 465 end 466 debug("(EnOceanPlugin::init) Running on Ethernet. IP = ".. ip ..", port = ".. port ..".") 467 luup.io.open(lul_device, ip, port) 468 else 469 debug("(EnOceanPlugin::init) Invalid IP. Running on Serial.") 470 end 471 end 472 ]] 511 if (DEBUG_MODE) then 512 debug = log 513 end 514 515 -- Get the sender ID of the TCM300. 516 addToSendQueue(PACKET_TYPES.COMMON_COMMAND, COMMON_COMMAND.CO_RD_IDBASE, "", true) 517 473 518 debug("(EnOceanPlugin::init) Success: startup successful") 474 519 return true, "startup successful", "EnOcean plugin" -
/trunk/I_EnOceanESP3.xml
r1 r3 10 10 11 11 -- Callbacks 12 clearTask = enoceanPlugin.clearTask13 sendMessage = enoceanPlugin.sendMessage12 handleRadioTelegram = enoceanPlugin.handleRadioTelegram 13 handleEventMessage = enoceanPlugin.handleEventMessage 14 14 15 15 return enoceanPlugin.init(lul_device)
Note: See TracChangeset
for help on using the changeset viewer.