{"id":17990368,"url":"https://github.com/suborb/huafan-wifiswitch","last_synced_at":"2025-06-23T17:08:33.345Z","repository":{"id":88571217,"uuid":"76142775","full_name":"suborb/huafan-wifiswitch","owner":"suborb","description":"Tools to control HuaFan WifiSwitch","archived":false,"fork":false,"pushed_at":"2017-01-07T14:03:03.000Z","size":10,"stargazers_count":6,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-20T22:23:27.206Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/suborb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-10T23:09:56.000Z","updated_at":"2022-06-18T16:16:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"83ea1608-908f-452b-bd43-4b82ae73f204","html_url":"https://github.com/suborb/huafan-wifiswitch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suborb%2Fhuafan-wifiswitch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suborb%2Fhuafan-wifiswitch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suborb%2Fhuafan-wifiswitch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/suborb%2Fhuafan-wifiswitch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/suborb","download_url":"https://codeload.github.com/suborb/huafan-wifiswitch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245561521,"owners_count":20635757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-29T19:17:39.961Z","updated_at":"2025-06-23T17:08:33.332Z","avatar_url":"https://github.com/suborb.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Huafan Wifi Switch\n\nThis is a cheap wifi switch controlled by an esp8266. By default it works via two servers located in China. These servers have complete control over the switch so if suspicious I'd recommend firewalling off the plugs.\n\nExample auction for them: http://www.ebay.co.uk/itm/Smart-WiFi-Wireless-Remote-Control-UK-Plug-Socket-Switch-Power-Mobile-Phone-App-/272277763047 (I didn't use this seller)\n\n## The script\n\nhfswitch.py allows the controlling of a switch and additionally allows usage statistics to me posted back to domoticz. For usage to work, the script should be run periodically.\n\n## Servers the firmware contacts:\n\n121.42.46.59 port 2110 and 5110. This is the main control host. Initially port 5110 is used, and then fails back to 2100. This runs a slightly different protocol to local usage.\n\n115.29.202.58 port 8000. The switch talks to one of the servers under this domain and regularly issues a HTTP ping.\n\n\n## Discovery\n\nPlugs can be discovered with a UDP broadcast message targetted at port 7682.\n\nContent of the broadcast message is:\n\n```\nHF\n```\n\nResponse will be received of the format:\n\n```\n\u003cmodel name\u003e,\u003cstate\u003e,\u003cIP address\u003e,\u003cMac address\u003e\n```\n\nfor example:\n\n```\nHF-W0B,2,192.168.4.1,00-00-00-00-00-00\n```\n\n\n## Controlling Protocol\n\nThe switch accepts a TCP connection on port 7681. The protocol is fairly simple, but is obfuscated using AES. The encryption key is \"9521314528002574\" and the IV is \"4528453102574529\".\n\n\n## Turning the Switch on\n\n### Command\n```\nP 888888 AT+SOPEN=1\\r\\n\n```\n### Response\n\n```\nS 000000000000 +SNODE:#1,1\n```\nWhere 000000000000 is the mac address and the final 1 is the state of the switch.\n\n## Turning the Switch off\n\n### Command\n```\nP 888888 AT+SCLOSE=1\\r\\n\n```\n### Response\n\n```\nS 000000000000 +SNODE:#1,2\n```\nWhere 000000000000 is the mac address and the final 2 is the state of the switch.\n\n## Reading the power state\n\n### Command\n```\nP 888888 AT+SCURRENTPOWER=1\\r\\n\n```\n### Response\n\n```\nS 000000000000 +SCURRENTPOWER:#1,1,WWWWWW,AAAAA\n```\n\nWhere 000000000000 is the mac address and the final 2 is the state of the switch.\n\nW is the wattage measured in 0.01W. A is the current in 0.0001A\n\n\n## Switching between AP and Client mode\n\n### Switch to standalone mode (AP)\n\n```\nP 888888 AT+SAPSTA=1\n```\n\n### Switch to station mode\n\n```\nP 888888 AT+SAPSTA=0\n```\n\n## Joining a network\n\nFrom inspection, the appropriate command is:\n\n```\nP 888888 AT+SSSIDINFO=[SSID Length],[SSID],[Auth mode],[password]\n```\n\nWhere [Auth mode] is one of the following values:\n\n* AuthModeOpen = 0;\n* AuthModeWPA = 3;\n* AuthModeWPAPSK = 4;\n* AuthModeWPA2 = 6;\n* AuthModeWPA2PSK = 7;\n* AuthModeWPA1WPA2 = 8;\n* AuthModeWPA1PSKWPA2PSK = 9;\n\nResponse is:\n\n```\nS 000000000000 +SSSIDINFO:OK\n```\n\nWhere 000000000000 is the mac address of the switch.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuborb%2Fhuafan-wifiswitch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuborb%2Fhuafan-wifiswitch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuborb%2Fhuafan-wifiswitch/lists"}