Trying to write a new plugin pulling my hair out.

I decided I wanted to open my Garage with the same RFID i use for work (HID RFID)

I have interfaced an old Ebay RFID reader to a Network POE Arduino. This is now run out to the garage with a single cat 5 cable. I can successfully connect to the Arduino on 192.168.1.177 on port 23 using putty, each time a card is scanned the Arduino spits out the card # followed by a crlf. So the hardware works great. The Arduino will take a few hundred separate connections at a time, if a card is scanned it will send it to all of the PC’s connected on port 23.

On to the Vera code.

I stole some code from the Sharp TV plugin, so you will see some left overs that I don’t think will hurt anything for now. Currently the code should just spit the scanned card # into the log. My end goal is to have one device added for each card that I would like to use. I would store the card number in the plugin and choose what that card will do via the Vera interface. (one card could just open the garage door while another could be used by the housekeeper to open the garage door, unlock the door from the garage to the house and disarm the home DSC alarm)

“I_ArdRFID.xml”

<?xml version="1.0"?>
<implementation>
    <settings>
        <protocol>crlf</protocol>
    </settings>

    <functions>


        function RFIDStartup(lul_device)
				
	    local ipAddress, trash, ipPort
luup.log("Starting ArdRFID")
				    if (string.match(luup.devices[lul_device].ip, "(^(.*)(:(%d+))$")) then
							ipAddress, trash, ipPort = string.match(luup.devices[lul_device].ip, "^(.*)(:(%d+))$")
				    else
								ipAddress = luup.devices[lul_device].ip
								ipPort = 23
								luup.log("Setting to default port 23 ArdRFID")
				    end

            if ((ipAddress ~= nil) and (ipAddress ~= "")) then
                luup.log("Running I_ArdRFID.xml")
                luup.io.open(lul_device, ipAddress, ipPort)
            else
                luup.log("No IP address specified for %s " .. tostring(lul_device))
            end
        end
    </functions>

    <incoming>
        <lua>
            luup.log("Received data from Arduino " .. tostring(lul_data))
        </lua>
    </incoming>

    <startup>RFIDStartup</startup>


</implementation>

“D_ArdRFID.json”

{
    "flashicon": "icons\/IR_Transmitter.swf",
    "imgIconBody": "",
    "imgIconDimmable": "",
    "imgIconTurnable": "",
    "imgIconMin": "",
    "imgIconMax": "",
    "halloIconsDir": "pics\/hallo",
    "inScene": "1",
    "DisplayStatus": {
		"Service": "urn:micasaverde-com:serviceId:DiscretePower1",
		"Variable": "Status",
		"MinValue": "0",
		"MaxValue": "1"
    },
    "doc_url": {
        "doc_language": 1,
        "doc_manual": 1,
        "doc_version": 1,
        "doc_platform": 0,
        "doc_page": "devices"
    },
    "ToggleButton": 1,
    "Tabs": [
        {
            "Label": {
                "lang_tag": "tabname_control",
                "text": "Control"
            },
            "Position": "0",
            "TabType": "flash",
            "SceneGroup": [
                {
                    "id": "1",
                    "top": "0.5",
                    "left": "0",
                    "x": "2",
                    "y": "2,5"
                }
            ],
            "ControlGroup": [
                {
                    "id": "1",
                    "isSingle": "1",
                    "scenegroup": "1"
                },
                {
                    "id": "2",
                    "isSingle": "1",
                    "scenegroup": "1"
                },
                {
                    "id": "3",
                    "isSingle": "1"
                }
            ],
            "Control": [
                {
                    "ControlGroup":"1",
                    "ControlType": "button",
                    "Label": {
                        "lang_tag": "cmd_off",
                        "text": "Off"
                    },
                    "top": "1.5",
		    "left": "0",
                    "Display": {
                        "Service": "urn:micasaverde-com:serviceId:DiscretePower1",
			"Value": "0",
			"Top": 90,
			"Left": 50,
			"Width": 75,
			"Height": 20
                    },
                    "Command": {
                        "Service": "urn:micasaverde-com:serviceId:DiscretePower1",
                        "Action": "Off"
                    }
                },
                {
                    "ControlGroup":"1",
                    "ControlType": "button",
                    "Label": {
                        "lang_tag": "cmd_on",
                        "text": "On"
                    },
                    "top": "1.5",
                    "left": "1",
                    "Display": {
                        "Service": "urn:micasaverde-com:serviceId:DiscretePower1",
                        "Variable": "Status",
			"Value": "1",
			"Top": 90,
			"Left": 145,
			"Width": 75,
			"Height": 20
                    },
                    "Command": {
                        "Service": "urn:micasaverde-com:serviceId:DiscretePower1",
                        "Action": "On"
                    }
                },
                {
	          "ControlType": "variable",
	          "Display": {
	          "Service": "urn:micasaverde-com:serviceId:InputSelection1",
	          "Variable": "Input",
	          "Top": 20,
	          "Left": 50,
	          "Width": 200,
	          "Height": 20
                   }
                },
	        {
	          "ControlType": "label",
	          "Label": {
	            "lang_tag": "device_control_page",
	            "text": "Volume:"
	          },
	          "Display": {
	            "Top": 30,
	            "Left": 50,
	            "Width": 120,
	            "Height": 20
	          }
                },
	        {
	          "ControlGroup": "2",
	          "ControlHeader": "1",
	          "ControlType": "slider",
	          "top": "0",
	          "left": "0",
	          "Display": {
	            "Service": "urn:micasaverde-com:serviceId:Volume2",
	            "Variable": "Volume",
	            "ID": "Volume",
	            "MinValue": "10",
	            "MaxValue": "60",
	            "Top": 45,
	            "Left": 50,
	            "Width": 200,
	            "Height": 20
	          },
	          "Command": {
	            "Service": "urn:micasaverde-com:serviceId:Volume2",
	            "Action": "SetVolume",
	            "Parameters": [
	              {
	                "Name": "newTargetValue",
	                "ID": "Volume"
	              }
	            ]
	          }
               },
                {
                    "ControlGroup":"3",
                    "ControlType": "button",
                    "Label": {
                        "lang_tag": "cmd_mute",
                        "text": "Mute"
                    },
                    "Display": {
                        "Service": "urn:micasaverde-com:serviceId:Volume2",
                        "Variable": "Status",
			"Value": "0",
			"Top": 45,
			"Left": 230,
			"Width": 75,
			"Height": 20
                    },
                    "Command": {
                        "Service": "urn:micasaverde-com:serviceId:Volume2",
                        "Action": "ToggleMute"
                    }
                },
            ]
        },
        {
            "Label": {
                "lang_tag": "settings",
                "text": "Settings"
            },
            "Position": "1",
            "TabType": "javascript",
            "ScriptName": "shared.js",
            "Function": "simple_device"
        },
        {
            "Label": {
                "lang_tag": "advanced",
                "text": "Advanced"
            },
            "Position": "2",
            "TabType": "javascript",
            "ScriptName": "shared.js",
            "Function": "advanced_device"
        },
    ],
    "DeviceType": "urn:schemas-micasaverde-com:device:RFID:1",
}

“D_ArdRFID.xml”

<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
  <specVersion>
    <major>1</major>
    <minor>0</minor>
  </specVersion>
  <device>
    <deviceType>urn:schemas-micasaverde-com:device:RFID:1</deviceType>
    <staticJson>D_ArdRFID.json</staticJson>
    <friendlyName>ArdRFID Interface</friendlyName>
    <manufacturer>Todd</manufacturer>
    <manufacturerURL>http://www.canadiangeek.com</manufacturerURL>
    <modelDescription>RFID interface made from Network Arduino</modelDescription>
    <modelName>Dont have one Yet</modelName>
    <modelNumber>1.0</modelNumber>
    <UDN>uuid:2ff93ec0-c2f8-11dd-ad8b-08fff0c9a37</UDN>
    <protocol>crlf</protocol>
    <handleChildren>1</handleChildren>

    <implementationList>
        <implementationFile>I_ArdRFID.xml</implementationFile>
    </implementationList>

    <serviceList>
    </serviceList>
  </device>
</root>

Now when I upload the files and run them i see this in the logs.

01 10/21/13 22:13:17.283 Device_LuaUPnP::LoadDeviceDoc #32 can’t parse name /uuid:4d494342-5342-5645-0020-000001c9d534 <0x2b026000>
01 10/21/13 22:13:17.283 JobHandler_LuaUPnP::CreateDevice_LuaUPnP failed to load 32/I_ArdRFID.xml so device 32 is offline <0x2b026000>
01 10/21/13 22:13:17.624 Device_LuaUPnP::CreateServices Aborting device 32 because the topmost device has no interface <0x2b026000>
01 10/21/13 22:13:17.624 JobHandler_LuaUPnP::CreateAllServices failed to create 32 <0x2b026000>
01 10/21/13 22:13:17.682 Device_LuaUPnP::CreateImplementations Aborting 32 because it failed to load <0x2b026000>
01 10/21/13 22:13:17.683 JobHandler_LuaUPnP::CreateAllImplementations failed to create 32 <0x2b026000>

Thoughts?

A couple of points that may help:

This not a micasaverde device:
urn:schemas-micasaverde-com:device:RFID:1

See:
http://wiki.mios.com/index.php/Luup_UPNP_Files#Device_Categories

Need to make up your own and then refer to it - eg:
urn:schemas-grifter-com:device:RFID:1

You can leave this line out as I believe Vera sorts this out. If you copied the code from somewhere else, then the UUID would no longer be unique.

uuid:2ff93ec0-c2f8-11dd-ad8b-08fff0c9a37

Also run your json file through a validator.

Thanks for the quick reply. I have now changed
urn:schemas-grifter-com:device:RFID:1
and the matching line in “DeviceType” line to “urn:schemas-micasaverde-com:device:GenericIO:1”

I had already randomly changed some numbers in the UDN uuidstring to make it unique.
uuid:2ff93ec0-c2f8-11dd-ad8b-08fff0c9a37

I tried uploading and testing again but get the same result.

Do you know of a JSON validator that works for vera json?
I tried testing the .JSON files on my vera (that are in working plugins) and they all fail validation on the standard online JSON validators.

Any JSON validator will work with the files used in Vera. Double check your formatting and walk through all the groupings you have. You likely misplaces a comma or something.

Also start ripping apart other plugins to get a good idea of what a properly formatted .json file looks like for Vera. That is what helped me.

Running your .json file through http://jsoneditoronline.org/ gives the following error:

Error: Parse error on line 175:
… },
]
},

----------------------^
Expecting ‘STRING’, ‘NUMBER’, ‘NULL’, ‘TRUE’, ‘FALSE’, ‘{’, ‘[’, got ‘]’

[quote=“grifter, post:3, topic:177467”]I have now changed
urn:schemas-grifter-com:device:RFID:1
and the matching line in “DeviceType” line to “urn:schemas-micasaverde-com:device:GenericIO:1”[/quote]

You must change the “DeviceType”: “urn:schemas-micasaverde-com:device:RFID:1” line from the json file too.

Thanks for you help guys, took me a while but i found the JSON problems.

New “D_ArdRFID.json” now passes validation

[code]{
“flashicon”: “icons/IR_Transmitter.swf”,
“imgIconBody”: “”,
“imgIconDimmable”: “”,
“imgIconTurnable”: “”,
“imgIconMin”: “”,
“imgIconMax”: “”,
“halloIconsDir”: “pics/hallo”,
“inScene”: “1”,
“DisplayStatus”: {
“Service”: “urn:micasaverde-com:serviceId:DiscretePower1”,
“Variable”: “Status”,
“MinValue”: “0”,
“MaxValue”: “1”
},
“doc_url”: {
“doc_language”: 1,
“doc_manual”: 1,
“doc_version”: 1,
“doc_platform”: 0,
“doc_page”: “devices”
},
“ToggleButton”: 1,

"Tabs": [
    {
      "Label": {
            "lang_tag": "tabname_control",
            "text": "Control"
        },
        "Position": "0",
        "TabType": "flash",
        "SceneGroup": [
            {
                "id": "1",
                "top": "0.5",
                "left": "0",
                "x": "2",
                "y": "2,5"
            }
        ],
        "ControlGroup": [
            {
                "id": "1",
                "isSingle": "1",
                "scenegroup": "1"
            },
            {
                "id": "2",
                "isSingle": "1",
                "scenegroup": "1"
            },
            {
                "id": "3",
                "isSingle": "1"
            }
        ],
        "Control": [
            {
                "ControlGroup":"1",
                "ControlType": "button",
                "Label": {
                    "lang_tag": "cmd_off",
                    "text": "Off"
                },
                "top": "1.5",
	            "left": "0",
                "Display": {
                    "Service": "urn:micasaverde-com:serviceId:DiscretePower1",
		            "Value": "0",
		            "Top": 90,
		            "Left": 50,
		            "Width": 75,
		            "Height": 20
                },
                "Command": {
                    "Service": "urn:micasaverde-com:serviceId:DiscretePower1",
                    "Action": "Off"
                }
            },
            {
                "ControlGroup":"1",
                "ControlType": "button",
                "Label": {
                    "lang_tag": "cmd_on",
                    "text": "On"
                },
                "top": "1.5",
                "left": "1",
                "Display": {
                    "Service": "urn:micasaverde-com:serviceId:DiscretePower1",
                    "Variable": "Status",
		            "Value": "1",
		            "Top": 90,
		            "Left": 145,
		            "Width": 75,
		            "Height": 20
                },
                "Command": {
                    "Service": "urn:micasaverde-com:serviceId:DiscretePower1",
                    "Action": "On"
                }
            },
            {
              "ControlType": "variable",
	          "Display": {
    	          "Service": "urn:micasaverde-com:serviceId:InputSelection1",
    	          "Variable": "Input",
    	          "Top": 20,
    	          "Left": 50,
    	          "Width": 200,
    	          "Height": 20
               }
            },
            {
	          "ControlType": "label",
	          "Label": {
	            "lang_tag": "device_control_page",
	            "text": "Volume:"
	          },
	          "Display": {
	            "Top": 30,
	            "Left": 50,
	            "Width": 120,
	            "Height": 20
	          }
            },
        {
          "ControlGroup": "2",
          "ControlHeader": "1",
          "ControlType": "slider",
          "top": "0",
          "left": "0",
          "Display": {
            "Service": "urn:micasaverde-com:serviceId:Volume2",
            "Variable": "Volume",
            "ID": "Volume",
            "MinValue": "10",
            "MaxValue": "60",
            "Top": 45,
            "Left": 50,
            "Width": 200,
            "Height": 20
          },
          "Command": {
            "Service": "urn:micasaverde-com:serviceId:Volume2",
            "Action": "SetVolume",
            "Parameters": [
              {
                "Name": "newTargetValue",
                "ID": "Volume"
              }
            ]
          }
        },
        {
            "ControlGroup":"3",
            "ControlType": "button",
            "Label": {
                "lang_tag": "cmd_mute",
                "text": "Mute"
            },
            "Display": {
                "Service": "urn:micasaverde-com:serviceId:Volume2",
                "Variable": "Status",
        		"Value": "0",
    			"Top": 45,
    			"Left": 230,
    			"Width": 75,
    			"Height": 20
            },
            "Command": {
                "Service": "urn:micasaverde-com:serviceId:Volume2",
                "Action": "ToggleMute"
            }
        }            
]
},
    {
        "Label": {
            "lang_tag": "settings",
            "text": "Settings"
        },
        "Position": "1",
        "TabType": "javascript",
        "ScriptName": "shared.js",
        "Function": "simple_device"
    },
    {
        "Label": {
            "lang_tag": "advanced",
            "text": "Advanced"
        },
        "Position": "2",
        "TabType": "javascript",
        "ScriptName": "shared.js",
        "Function": "advanced_device"
    }



   ],
   "DeviceType": "urn:schemas-micasaverde-com:device:GenericIO:1"

}[/code]

D_ArdRFID.xml

[code]<?xml version="1.0"?>


1
0


urn:schemas-micasaverde-com:device:GenericIO:1
D_ArdRFID.json
ArdRFID Interface
Todd
http://www.canadiangeek.com
RFID interface made from Network Arduino
Dont have one Yet
1.0
uuid:2ff93ec0-c2f8-11dd-ad8b-09EEf0c9a37
crlf
1

<implementationList>
    <implementationFile>I_ArdRFID.xml</implementationFile>
</implementationList>

<serviceList>
</serviceList>
[/code]

I_ArdRFID.xml

[code]<?xml version="1.0"?>


crlf

<functions>


    function RFIDStartup(lul_device)
			
    local ipAddress, trash, ipPort

luup.log(“Starting ArdRFID”)
if (string.match(luup.devices[lul_device].ip, “(^(.)(:(%d+))$")) then
ipAddress, trash, ipPort = string.match(luup.devices[lul_device].ip, "^(.
)(:(%d+))$”)
else
ipAddress = luup.devices[lul_device].ip
ipPort = 23
luup.log(“Setting to default port 23 ArdRFID”)
end

        if ((ipAddress ~= nil) and (ipAddress ~= "")) then
            luup.log("Running I_ArdRFID.xml")
            luup.io.open(lul_device, ipAddress, ipPort)
        else
            luup.log("No IP address specified for %s " .. tostring(lul_device))
        end
    end
</functions>

<incoming>
    <lua>
        luup.log("Received data from Arduino " .. tostring(lul_data))
    </lua>
</incoming>

<startup>RFIDStartup</startup>
[/code]

Same problem as before

01      10/21/13 23:30:29.385   Device_LuaUPnP::LoadDeviceDoc #32 can't parse name /uuid:4d494342-5342-5645-0020-000001c9d534 <0x2b3f6000>
01      10/21/13 23:30:29.385   JobHandler_LuaUPnP::CreateDevice_LuaUPnP failed to load 32/I_ArdRFID.xml so device 32 is offline <0x2b3f6000>
01      10/21/13 23:30:29.723   Device_LuaUPnP::CreateServices Aborting device 32 because the topmost device has no interface <0x2b3f6000>
01      10/21/13 23:30:29.723   JobHandler_LuaUPnP::CreateAllServices failed to create 32 <0x2b3f6000>
01      10/21/13 23:30:29.781   Device_LuaUPnP::CreateImplementations Aborting 32 because it failed to load <0x2b3f6000>
01      10/21/13 23:30:29.781   JobHandler_LuaUPnP::CreateAllImplementations failed to create 32 <0x2b3f6000>

I’m starting to think there is nothing wrong with the code just my device setup. The error says failed to load “32/I_ArdRFID.xml”, is it trying to load that file from a directory called 32? can someone try uploading these files to their vera and let me know if the device starts for them?

Breakthrough

I had the device setup wrong.
D_ArdRFID.xml is now setup as the device file and
I_ArdRFID.xml is now setup as the impl_file.

and it made it past that error, new problems but now I can start to work on them.