-
Notifications
You must be signed in to change notification settings - Fork 0
HowTo: Use Phantom.NET
chuangen edited this page Oct 1, 2014
·
1 revision
PhantomConfiguration config = PhantomConfiguration.Default;
config.AppId = "9aa886e3a8a7d93a23136772835f1f40"; //客户端的app-id
config.AppSecret = "963bb7362c4cb3d4e3af86da4eb10fac"; //客户端的app-secret
config.UserAgent = "chuangen@live.cn/1.0.0 (Windows 8.1)"; //客户端的User-Agent
config.RequestInterval = 2000; //刷新灯泡状态的请求间隔(毫秒)
PhantomClient client = new PhantomClient();
Token token = client.Login(userName, password);
string accessToken = token.AccessToken; //请保存该字符串,以便下次使用
提示:一旦得到令牌,请保存令牌字符串,下次无需登录即可进行操作。
client.Connect(accessToken);//连接服务
//查看场景列表
foreach(Scenario item in client.Scenarios)
{ }
//应用某个场景
client.SetScenario(scenario);
//查看灯泡列表
foreach(Bulb item in client.Bulbs)
{ }
//点亮灯泡
client.SetBulb(bulb, true);
//关闭灯泡
client.SetBulb(bulb, false);
//设置灯泡的亮度和色温
client.SetBulb(bulb, brightness, hue);
client.NewScenario += client_NewScenario; //添加了新场景时
client.ScenarioRemoved += client_ScenarioRemoved;//删除了场景时
client.ScenarioStateChanged += client_ScenarioStateChanged;//场景的信息变化时(如重命名后)
client.NewBulb += client_NewBulb; //添加了新灯泡时
client.BulbRemoved += client_BulbRemoved; //删除了灯泡设备时
client.BulbStateChanged += client_BulbStateChanged; //灯泡状态变化时(上下线、开关、亮度变化等)