Skip to content

Commit

Permalink
mqtt publish gpio and keyboard working
Browse files Browse the repository at this point in the history
  • Loading branch information
talkkonnect committed Jan 16, 2022
1 parent 763ee23 commit a18cb57
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
10 changes: 8 additions & 2 deletions gpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,10 @@ func (b *Talkkonnect) initGPIO() {
} else {
log.Println("debug: MQTT0 Button is pressed")
playIOMedia("iomqtt0")
//mqtt button0 send command placeholder
MQTTButtonCommand := findMQTTButton("0")
if MQTTButtonCommand.Enabled {
MQTTPublish(MQTTButtonCommand.Payload)
}
time.Sleep(150 * time.Millisecond)
}
}
Expand All @@ -646,7 +649,10 @@ func (b *Talkkonnect) initGPIO() {
} else {
log.Println("debug: MQTT1 Button is pressed")
playIOMedia("iomqtt1")
//mqtt button1 send command placeholder
MQTTButtonCommand := findMQTTButton("1")
if MQTTButtonCommand.Enabled {
MQTTPublish(MQTTButtonCommand.Payload)
}
time.Sleep(150 * time.Millisecond)
}
}
Expand Down
5 changes: 5 additions & 0 deletions usbkeyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ func (b *Talkkonnect) USBKeyboard() {
playIOMedia("usbvoicetarget")
b.cmdSendVoiceTargets(uint32(voicetarget))
}
case "mqttpubpayloadset":
if USBKeyMap[rune(ke.Scancode)].ParamName == "payloadvalue" {
playIOMedia("usbmqttpubpayloadset")
MQTTPublish(USBKeyMap[rune(ke.Scancode)].ParamValue)
}
default:
log.Println("error: Command Not Defined ", strings.ToLower(USBKeyMap[rune(ke.Scancode)].Command))
}
Expand Down
9 changes: 9 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,3 +466,12 @@ func checkSBCVersion() string {

return string(fileContent[:])
}

func findMQTTButton(findMQTTButton string) mqttPubButtonStruct {
for _, button := range Config.Global.Software.RemoteControl.MQTT.Settings.Pubpayload.Mqtt {
if button.Item == findMQTTButton && button.Enabled {
return mqttPubButtonStruct{button.Item, button.Payload, button.Enabled}
}
}
return mqttPubButtonStruct{"", "", false}
}
8 changes: 2 additions & 6 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@
package talkkonnect

const (
talkkonnectVersion string = "2.08.03"
talkkonnectVersion string = "2.08.04"
talkkonnectReleased string = "Jan 16 2022"
)

/* Release Notes
1. In Client.go moved the stream on start and tx on start with possible delay to the last item to run before keylistener
2. Now we can check board type and version and show in the talkkonnect banner screen
3. Fixed State Tracking of Cancellable Stream
4. Client.go stricter checking of gps enabled and traccar enabled before firing off go routines for handling gpstracking and traccar
5. Fix the update-talkkonnect.sh script to delete only the talkkonnect binary and not whole binary folder for faster use with vs code
1. Added MQTT Buttons to config, gpio, usbkeyboard and ttykeyboard
*/
15 changes: 14 additions & 1 deletion xmlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ type ConfigStruct struct {
MQTTRetained bool `xml:"retained"`
MQTTAttentionBlinkTimes int `xml:"attentionblinktimes"`
MQTTAttentionBlinkmsecs int `xml:"attentionblinkmsecs"`
Pubpayload struct {
Mqtt []struct {
Item string `xml:"item,attr"`
Payload string `xml:"payload,attr"`
Enabled bool `xml:"enabled,attr"`
} `xml:"mqtt"`
} `xml:"pubpayload"`
} `xml:"settings"`
Commands struct {
Command []struct {
Expand Down Expand Up @@ -544,6 +551,12 @@ type talkingStruct struct {
WhoTalking string
}

type mqttPubButtonStruct struct {
Item string
Payload string
Enabled bool
}

// Generic Global Config Variables
var Config ConfigStruct
var ConfigXMLFile string
Expand Down Expand Up @@ -1575,7 +1588,7 @@ func CheckConfigSanity(reloadxml bool) {

for index, keyboard := range Config.Global.Hardware.Keyboard.Command {
if keyboard.Enabled {
if !(keyboard.Action == "channelup" || keyboard.Action == "channeldown" || keyboard.Action == "serverup" || keyboard.Action == "serverdown" || keyboard.Action == "mute" || keyboard.Action == "unmute" || keyboard.Action == "mute-toggle" || keyboard.Action == "stream-toggle" || keyboard.Action == "volumeup" || keyboard.Action == "volumedown" || keyboard.Action == "setcomment" || keyboard.Action == "transmitstart" || keyboard.Action == "transmitstop" || keyboard.Action == "record" || keyboard.Action == "voicetargetset") || keyboard.Action == "volup" || keyboard.Action == "voldown" {
if !(keyboard.Action == "channelup" || keyboard.Action == "channeldown" || keyboard.Action == "serverup" || keyboard.Action == "serverdown" || keyboard.Action == "mute" || keyboard.Action == "unmute" || keyboard.Action == "mute-toggle" || keyboard.Action == "stream-toggle" || keyboard.Action == "volumeup" || keyboard.Action == "volumedown" || keyboard.Action == "setcomment" || keyboard.Action == "transmitstart" || keyboard.Action == "transmitstop" || keyboard.Action == "record" || keyboard.Action == "voicetargetset" || keyboard.Action == "volup" || keyboard.Action == "voldown" || keyboard.Action == "mqttpubpayloadset") {
log.Printf("warn: Config Error [Section Keyboard] Enabled Keyboard Action %v Invalid\n", keyboard.Action)
Config.Global.Hardware.Keyboard.Command[index].Enabled = false
Warnings++
Expand Down

0 comments on commit a18cb57

Please sign in to comment.