请问:树莓派 如何通过blinker 使用小爱语音控制?-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1793|回复: 3

[已解答] 请问:树莓派 如何通过blinker 使用小爱语音控制?

[复制链接]
发表于 2021-3-29 22:04 | 显示全部楼层 |阅读模式
本帖最后由 jinkecy 于 2021-3-29 22:37 编辑

请问:树莓派 如何通过blinker 使用小爱语音控制?
我用了例子中到: AliGenie_LIGHT.py
可是小爱  --米家  同步设备 没有出现改设备。 另外,我使用 8266 就可以显示。
不知道哪里不对,请指点
 楼主| 发表于 2021-3-29 22:13 | 显示全部楼层
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from Blinker.Blinker import Blinker, BlinkerButton, BlinkerNumber, BlinkerAliGenie
  4. from Blinker.BlinkerConfig import *
  5. from Blinker.BlinkerDebug import *

  6. auth = 'Your Device Secret Key'

  7. BLINKER_DEBUG.debugAll()

  8. Blinker.mode('BLINKER_WIFI')
  9. Blinker.aliType('BLINKER_ALIGENIE_LIGHT')
  10. Blinker.begin(auth)

  11. button1 = BlinkerButton('btn-abc')
  12. number1 = BlinkerNumber('num-abc')

  13. counter = 0
  14. wsState = 'on'
  15. wsMode = BLINKER_CMD_COMMON

  16. def aligeniePowerState(state):
  17.     ''' '''

  18.     BLINKER_LOG('need set power state: ', state)

  19.     BlinkerAliGenie.powerState(state)
  20.     BlinkerAliGenie.print()

  21. def aligenieColor(color):
  22.     ''' '''

  23.     BLINKER_LOG('need set color: ', color)

  24.     # if color == 'Red':
  25.     #     # your codes
  26.     # elif color == 'Yellow':
  27.     #     # your codes
  28.     # elif color == 'Blue':
  29.     #     # your codes
  30.     # elif color == 'Green':
  31.     #     # your codes
  32.     # elif color == 'White':
  33.     #     # your codes
  34.     # elif color == 'Black':
  35.     #     # your codes
  36.     # elif color == 'Cyan':
  37.     #     # your codes
  38.     # elif color == 'Purple':
  39.     #     # your codes
  40.     # elif color == 'Orange':
  41.     #     # your codes

  42.     BlinkerAliGenie.color(color)
  43.     BlinkerAliGenie.print()

  44. def aligenieMode(mode):
  45.     ''' '''

  46.     BLINKER_LOG('need set mode: ', mode)

  47.     # if mode == BLINKER_CMD_ALIGENIE_READING:
  48.     #     # Your mode function
  49.     # elif mode == BLINKER_CMD_ALIGENIE_MOVIE:
  50.     #     # Your mode function
  51.     # elif mode == BLINKER_CMD_ALIGENIE_SLEEP:
  52.     #     # Your mode function
  53.     # elif mode == BLINKER_CMD_ALIGENIE_HOLIDAY:
  54.     #     # Your mode function
  55.     # elif mode == BLINKER_CMD_ALIGENIE_MUSIC:
  56.     #     # Your mode function
  57.     # elif mode == BLINKER_CMD_ALIGENIE_COMMON:
  58.     #     # Your mode function

  59.     BlinkerAliGenie.mode(mode)
  60.     BlinkerAliGenie.print()

  61. def aligeniecMode(cmode):
  62.     ''' '''

  63.     BLINKER_LOG('need cancel mode: ', cmode)

  64.     # if mode == BLINKER_CMD_ALIGENIE_READING:
  65.     #     # Your mode function
  66.     # elif mode == BLINKER_CMD_ALIGENIE_MOVIE:
  67.     #     # Your mode function
  68.     # elif mode == BLINKER_CMD_ALIGENIE_SLEEP:
  69.     #     # Your mode function
  70.     # elif mode == BLINKER_CMD_ALIGENIE_HOLIDAY:
  71.     #     # Your mode function
  72.     # elif mode == BLINKER_CMD_ALIGENIE_MUSIC:
  73.     #     # Your mode function
  74.     # elif mode == BLINKER_CMD_ALIGENIE_COMMON:
  75.     #     # Your mode function

  76.     BlinkerAliGenie.mode(cMode)
  77.     BlinkerAliGenie.print()

  78. def aligenieBright(bright):
  79.     ''' '''

  80.     BLINKER_LOG('need set brightness: ', bright)

  81.     BlinkerAliGenie.brightness(bright)
  82.     BlinkerAliGenie.print()

  83. def aligenieRelativeBright(bright):
  84.     ''' '''

  85.     BLINKER_LOG('need set relative brightness: ', bright)

  86.     BlinkerAliGenie.brightness(bright)
  87.     BlinkerAliGenie.print()

  88. def aligenieColorTemp(colorTemp):
  89.     ''' '''

  90.     BLINKER_LOG('need set colorTemperature: ', colorTemp)

  91.     BlinkerAliGenie.colorTemp(colorTemp)
  92.     BlinkerAliGenie.print()

  93. def aligenieRelativeColorTemp(colorTemp):
  94.     ''' '''

  95.     BLINKER_LOG('need set relative colorTemperature: ', colorTemp)

  96.     BlinkerAliGenie.colorTemp(colorTemp)
  97.     BlinkerAliGenie.print()

  98. def aligenieQuery(queryCode):
  99.     ''' '''

  100.     BLINKER_LOG('AliGenie Query codes: ', queryCode)

  101.     if queryCode == BLINKER_CMD_QUERY_ALL_NUMBER :
  102.         BLINKER_LOG('AliGenie Query All')
  103.         BlinkerAliGenie.powerState(wsState)
  104.         BlinkerAliGenie.color(getColor())
  105.         BlinkerAliGenie.mode(wsMode)
  106.         BlinkerAliGenie.colorTemp(50)
  107.         BlinkerAliGenie.brightness(100)
  108.         BlinkerAliGenie.print()
  109.     elif queryCode == BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
  110.         BLINKER_LOG('AliGenie Query Power State')
  111.         BlinkerAliGenie.powerState(wsState)
  112.         BlinkerAliGenie.print()
  113.     elif queryCode == BLINKER_CMD_QUERY_COLOR_NUMBER :
  114.         BLINKER_LOG('AliGenie Query Color')
  115.         BlinkerAliGenie.color('red')
  116.         BlinkerAliGenie.print()
  117.     elif queryCode == BLINKER_CMD_QUERY_MODE_NUMBER :
  118.         BLINKER_LOG('AliGenie Query Mode')
  119.         BlinkerAliGenie.mode(wsMode)
  120.         BlinkerAliGenie.print()
  121.     elif queryCode == BLINKER_CMD_QUERY_COLORTEMP_NUMBER :
  122.         BLINKER_LOG('AliGenie Query ColorTemperature')
  123.         BlinkerAliGenie.colorTemp(50)
  124.         BlinkerAliGenie.print()
  125.     elif queryCode == BLINKER_CMD_QUERY_BRIGHTNESS_NUMBER :
  126.         BLINKER_LOG('AliGenie Query Brightness')
  127.         BlinkerAliGenie.brightness(100)
  128.         BlinkerAliGenie.print()
  129.     else :
  130.         BlinkerAliGenie.powerState(wsState)
  131.         BlinkerAliGenie.color('red')
  132.         BlinkerAliGenie.mode(wsMode)
  133.         BlinkerAliGenie.colorTemp(50)
  134.         BlinkerAliGenie.brightness(100)
  135.         BlinkerAliGenie.print()

  136. def button1_callback(state):
  137.     ''' '''

  138.     BLINKER_LOG('get button state: ', state)

  139.     button1.icon('icon_1')
  140.     button1.color('#FFFFFF')
  141.     button1.text('Your button name or describe')
  142.     button1.print(state)

  143. def data_callback(data):
  144.     global counter
  145.    
  146.     BLINKER_LOG('Blinker readString: ', data)
  147.     counter += 1
  148.     number1.print(counter)

  149. button1.attach(button1_callback)
  150. Blinker.attachData(data_callback)

  151. BlinkerAliGenie.attachPowerState(aligeniePowerState)
  152. BlinkerAliGenie.attachColor(aligenieColor)
  153. BlinkerAliGenie.attachMode(aligenieMode)
  154. BlinkerAliGenie.attachCancelMode(aligeniecMode)
  155. BlinkerAliGenie.attachBrightness(aligenieBright)
  156. BlinkerAliGenie.attachRelativeBrightness(aligenieRelativeBright)
  157. BlinkerAliGenie.attachColorTemperature(aligenieColorTemp)
  158. BlinkerAliGenie.attachRelativeColorTemperature(aligenieRelativeColorTemp)
  159. BlinkerAliGenie.attachQuery(aligenieQuery)

  160. if __name__ == '__main__':

  161.     while True:
  162.         Blinker.run()
复制代码
发表于 2021-3-29 23:10 | 显示全部楼层
天猫精灵的设备能在米家同步到才有问题。。。。。。。
 楼主| 发表于 2021-3-30 21:24 | 显示全部楼层
三水 发表于 2021-3-29 23:10
天猫精灵的设备能在米家同步到才有问题。。。。。。。

我不明白你到意思,树莓派数天猫精灵到,还是我用到程序不对?
应该用哪个呢? 11.jpg
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 13:52 , Processed in 0.093415 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表