我知道这是一个不起眼的用例,但我希望了解正在发生的事情......
所以我有一个家庭自动化服务器(Vera by MiCasaVerde)我可以做一个简单的http请求,它会返回一个(有点大的)JSON,如果你感兴趣的话就像一个(非常熟悉的)调用像这样:
http://10.0.1.25:3480/data_request?id=status&output_format=json&DeviceNum=3
或使用其"魔法"端口解析我可以这样调用端口80:
http://10.0.1.25/port_3480/data_request?id=status&output_format=json&DeviceNum=3
返回一个像这样的JSON对象:
{
"Device_Num_3":{
"states":[
{
"id":377,
"service":"urn:upnp-org:serviceId:HVAC_FanOperatingMode1",
"variable":"Mode",
"value":"Auto"
},
{
"id":378,
"service":"urn:micasaverde-com:serviceId:HVAC_OperatingState1",
"variable":"ModeState",
"value":"Cooling"
},
{
"id":379,
"service":"urn:micasaverde-com:serviceId:HVAC_OperatingState1",
"variable":"ModeStateForEnergy",
"value":"1"
},
{
"id":380,
"service":"urn:upnp-org:serviceId:HVAC_UserOperatingMode1",
"variable":"ModeStatus",
"value":"CoolOn"
},
{
"id":381,
"service":"urn:upnp-org:serviceId:HVAC_UserOperatingMode1",
"variable":"ModeTarget",
"value":"CoolOn"
},
{
"id":382,
"service":"urn:upnp-org:serviceId:TemperatureSensor1",
"variable":"CurrentTemperature",
"value":"76"
},
{
"id":383,
"service":"urn:upnp-org:serviceId:TemperatureSetpoint1",
"variable":"AllSetpoints",
"value":"40.000000,75.000000,0.000000"
},
{
"id":384,
"service":"urn:upnp-org:serviceId:TemperatureSetpoint1",
"variable":"CurrentSetpoint",
"value":"75"
},
{
"id":385,
"service":"urn:upnp-org:serviceId:TemperatureSetpoint1",
"variable":"SetpointTarget",
"value":"75.0"
},
{
"id":386,
"service":"urn:upnp-org:serviceId:TemperatureSetpoint1_Cool",
"variable":"CurrentSetpoint",
"value":"75"
},
{
"id":387,
"service":"urn:micasaverde-com:serviceId:HaDevice1",
"variable":"Configured",
"value":"1"
},
{
"id":388,
"service":"urn:micasaverde-com:serviceId:HaDevice1",
"variable":"ModeSetting",
"value":"1:;2:;3:;4:"
},
{
"id":389,
"service":"urn:micasaverde-com:serviceId:HaDevice1",
"variable":"LastUpdate",
"value":"1438438497"
},
{
"id":390,
"service":"urn:micasaverde-com:serviceId:HaDevice1",
"variable":"FirstConfigured",
"value":"1438438497"
},
{
"id":391,
"service":"urn:micasaverde-com:serviceId:HaDevice1",
"variable":"LastTimeCheck",
"value":"1469292556"
},
{
"id":392,
"service":"urn:micasaverde-com:serviceId:HaDevice1",
"variable":"LastTimeOffset",
"value":"-4"
},
{
"id":393,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"ManufacturerInfo",
"value":"16,1,2"
},
{
"id":394,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"Capabilities",
"value":"210,156,0,4,8,6,L,R,B,RS,|49:1,64:1,66,67,68,69,112,114,118,129,133,134,"
},
{
"id":395,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"NodeInfo",
"value":"31,40,42,43,44,45,70,72,76,81,85,86,"
},
{
"id":396,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"SetPointInfo",
"value":"H1,C1,"
},
{
"id":397,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"ConfiguredAssoc",
"value":""
},
{
"id":398,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"PollSettings",
"value":"60"
},
{
"id":399,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"VersionInfo",
"value":"6,2,64,20,9"
},
{
"id":400,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"Neighbors",
"value":"1,3,4,5,6,7,8,9,12,13,14,15,16,17,26,27,31,32,33,34,35,"
},
{
"id":401,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"LastReset",
"value":"1438438497"
},
{
"id":402,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"AssociationNum",
"value":"1"
},
{
"id":403,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"TemperatureScale",
"value":"0,1,1"
},
{
"id":404,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"PollOk",
"value":"43881"
},
{
"id":405,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"LastRouteUpdate",
"value":"1469322032"
},
{
"id":406,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"PollNoReply",
"value":"880"
},
{
"id":407,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"LastNnu",
"value":"1469340000,714"
},
{
"id":408,
"service":"urn:micasaverde-com:serviceId:ZWaveDevice1",
"variable":"LastArr",
"value":"1469340000,714"
},
{
"id":409,
"service":"urn:micasaverde-com:serviceId:ZWaveNetwork1",
"variable":"ConsecutivePollFails",
"value":"0"
},
{
"id":410,
"service":"urn:micasaverde-com:serviceId:GenericSensor1",
"variable":"CurrentLevel",
"value":"79"
}
],
"Jobs":[
],
"PendingJobs":0,
"tooltip":{
"display":0
},
"status":-1
},
"Using_2G":0,
"LoadTime":1469220487,
"DataVersion":220509446,
"UserData_DataVersion":220487076,
"TimeStamp":1469361166,
"lights_on":2,
"lights_off":9,
"doors_locked":5,
"doors_unlocked":2,
"sensors_tripped":0,
"sensors_not_tripped":8,
"failed_devices":8,
"visible_devices":93,
"partitions_active":0,
"partitions_notactive":2,
"alerts":[
{
"PK_Device":154,
"Room":10,
"DeviceName":"Laundry Door Lock",
"DeviceType":"urn:schemas-micasaverde-com:device:DoorLock:1",
"PK_Alert":"4802550961",
"LocalDate":"2016-07-22 17:26:22",
"EventType":4,
"SourceType":4,
"Argument":0,
"Filesize":0,
"Severity":2,
"LocalTimestamp":1469222782,
"Code":"DL_LOW_BATTERY",
"NewValue":"1",
"Description":"Laundry Door Lock",
"Users":"",
"Server_Storage":"",
"Key":"",
"Icon":"",
"PK_Store":"0"
},
{
"PK_Device":154,
"Room":10,
"DeviceName":"Laundry Door Lock",
"DeviceType":"urn:schemas-micasaverde-com:device:DoorLock:1",
"PK_Alert":"4802551121",
"LocalDate":"2016-07-22 17:26:22",
"EventType":4,
"SourceType":4,
"Argument":0,
"Filesize":0,
"Severity":2,
"LocalTimestamp":1469222782,
"Code":"DL_VERY_LOW_BATTERY",
"NewValue":"1",
"Description":"Laundry Door Lock",
"Users":"",
"Server_Storage":"",
"Key":"",
"Icon":"",
"PK_Store":"0"
},
{
"PK_Device":154,
"Room":10,
"DeviceName":"Laundry Door Lock",
"DeviceType":"urn:schemas-micasaverde-com:device:DoorLock:1",
"PK_Alert":"4802551251",
"LocalDate":"2016-07-22 17:26:22",
"EventType":4,
"SourceType":4,
"Argument":0,
"Filesize":0,
"Severity":2,
"LocalTimestamp":1469222782,
"Code":"SL_BATTERYALARM",
"NewValue":"0",
"Description":"Laundry Door Lock",
"Users":"",
"Server_Storage":"",
"Key":"",
"Icon":"",
"PK_Store":"0"
},
{
"PK_Device":150,
"Room":23,
"DeviceName":"Kids Bath Motion",
"DeviceType":"urn:schemas-micasaverde-com:device:MotionSensor:1",
"PK_Alert":"4802551401",
"LocalDate":"2016-07-22 17:26:22",
"EventType":4,
"SourceType":4,
"Argument":0,
"Filesize":0,
"Severity":2,
"LocalTimestamp":1469222782,
"Code":"SL_BATTERYALARM",
"NewValue":"10",
"Description":"Kids Bath Motion",
"Users":"",
"Server_Storage":"",
"Key":"",
"Icon":"",
"PK_Store":"0"
},
{
"PK_Device":59,
"Room":17,
"DeviceName":"GH Garage Door",
"DeviceType":"urn:schemas-micasaverde-com:device:DoorSensor:1",
"PK_Alert":"4802562881",
"LocalDate":"2016-07-22 17:27:46",
"EventType":4,
"SourceType":4,
"Argument":0,
"Filesize":0,
"Severity":1,
"LocalTimestamp":1469222866,
"Code":"DL_ARMEDTRIPPED",
"NewValue":"0",
"Description":"GH Garage Door",
"Users":"",
"Server_Storage":"",
"Key":"",
"Icon":"",
"PK_Store":"0"
},
{
"PK_Device":59,
"Room":17,
"DeviceName":"GH Garage Door",
"DeviceType":"urn:schemas-micasaverde-com:device:DoorSensor:1",
"PK_Alert":"4803130171",
"LocalDate":"2016-07-22 18:27:24",
"EventType":12,
"SourceType":3,
"Argument":0,
"Filesize":0,
"Severity":0,
"LocalTimestamp":1469226444,
"Code":"",
"NewValue":"1",
"Description":"",
"Users":"",
"Server_Storage":"",
"Key":"",
"Icon":"burglar.png",
"PK_Store":"0"
},
{
"PK_Device":59,
"Room":17,
"DeviceName":"GH Garage Door",
"DeviceType":"urn:schemas-micasaverde-com:device:DoorSensor:1",
"PK_Alert":"4803130271",
"LocalDate":"2016-07-22 18:27:24",
"EventType":3,
"SourceType":3,
"Argument":0,
"Filesize":0,
"Severity":1,
"LocalTimestamp":1469226444,
"Code":"DL_ARMEDTRIPPED",
"NewValue":"1",
"Description":"",
"Users":"1061485",
"Server_Storage":"",
"Key":"",
"Icon":"",
"PK_Store":"0"
},
{
"PK_Device":79,
"Room":19,
"DeviceName":"Main_Garage",
"DeviceType":"urn:schemas-upnp-org:device:DigitalSecurityCamera:1",
"PK_Alert":"4803134431",
"LocalDate":"2016-07-22 18:27:54",
"EventType":2,
"SourceType":1,
"Argument":0,
"Filesize":5055210,
"Severity":0,
"LocalTimestamp":1469226474,
"Code":"",
"NewValue":"",
"Description":"Main_Garage",
"Users":"",
"Server_Storage":"vera-us-oem-storage11.mios.com",
"Key":"1085348817",
"Icon":"camera.png",
"PK_Store":"1017965291",
"Format":"mp4"
},
{
"PK_Device":59,
"Room":17,
"DeviceName":"GH Garage Door",
"DeviceType":"urn:schemas-micasaverde-com:device:DoorSensor:1",
"PK_Alert":"4803142721",
"LocalDate":"2016-07-22 18:28:48",
"EventType":4,
"SourceType":4,
"Argument":0,
"Filesize":0,
"Severity":1,
"LocalTimestamp":1469226528,
"Code":"DL_ARMEDTRIPPED",
"NewValue":"0",
"Description":"GH Garage Door",
"Users":"",
"Server_Storage":"",
"Key":"",
"Icon":"",
"PK_Store":"0"
},
{
"PK_Device":78,
"Room":3,
"DeviceName":"Front Door L\/R",
"DeviceType":"urn:schemas-micasaverde-com:device:DoorLock:1",
"PK_Alert":"4817901641",
"LocalDate":"2016-07-23 22:59:56",
"EventType":4,
"SourceType":4,
"Argument":0,
"Filesize":0,
"Severity":3,
"LocalTimestamp":1469329196,
"Code":"DL_USERCODE",
"NewValue":"UserID=\"1\" UserName=\"Main\"",
"Description":"Front Door L\/R",
"Users":"",
"Server_Storage":"",
"Key":"",
"Icon":"",
"PK_Store":"0"
}
],
"ZWaveStatus":1,
"Mode":1,
"LocalTime":"2016-07-24 07:52:46 D"
}
这告诉我关于我的空调器的一切,这是由Z-Wave恒温器控制的。
现在,该服务器不允许JQuery(即$.getJSON()
)请求,因为它似乎需要身份验证才能使JavaScript功能正常工作。此外,CORS不是一个选项,因为它不受服务器支持。
我被建议1)为服务器创建代理或2)在服务器(Vera)上安装JavaScript库。这些东西都不能用于大量研究,也可能在我的网络服务器上添加软件。等
这对我来说似乎很奇怪,因为我可以将任何未经过身份验证的http请求(在我的浏览器中输入上述链接)发送到此服务器并将数据恢复到我的浏览器中。
有人有建议吗?我的想法是在我的Mac服务器上使用Raspberry Pi甚至脚本来查询Vera服务器......但是我担心我会遇到同样的问题。
有人可以向我解释一下我的局域网上的任何浏览器都可以发出http请求并得到解答,但是我无法使用JavaScript从我的网站获得相同的功能吗?