Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write not updating Characteristic Value #199

Open
Alex-ReachIndustries opened this issue Sep 27, 2023 · 1 comment
Open

Write not updating Characteristic Value #199

Alex-ReachIndustries opened this issue Sep 27, 2023 · 1 comment

Comments

@Alex-ReachIndustries
Copy link

So a little bit of an odd one here... I've followed what I've seen everywhere else and as far as I can tell everything makes sense, however when I call Characteristic.Write([]byte) from within the golang server side the characteristic value is not being updated and when read by an external device the value has indeed not updated. No errors or panics are being triggered, additionally, the fmt.Print inside the WriteEvent for the serverCharacteristic is being triggered, and when an external device writes to the clientCharacteristic it does update. Any ideas? Have I missed something really obvious?

...
        var serverCharacteristic bluetooth.Characteristic
	var clientCharacteristic bluetooth.Characteristic
	must("add service", adapter.AddService(&bluetooth.Service{
		UUID: serviceUUID,
		Characteristics: []bluetooth.CharacteristicConfig{
			{
				Handle: &serverCharacteristic,
				UUID:   serverUUID,
				Value:  currentResp,
				Flags:  bluetooth.CharacteristicReadPermission | bluetooth.CharacteristicWritePermission | bluetooth.CharacteristicWriteWithoutResponsePermission | bluetooth.CharacteristicWritePermission,
				WriteEvent: func(client bluetooth.Connection, offset int, value []byte) {
					fmt.Print("value: ", string(value))
					currentResp = value
				},
			},
			{
				Handle: &clientCharacteristic,
				UUID:   clientUUID,
				Value:  currentClient,
				Flags:  bluetooth.CharacteristicReadPermission | bluetooth.CharacteristicWritePermission | bluetooth.CharacteristicWriteWithoutResponsePermission | bluetooth.CharacteristicWritePermission,
				WriteEvent: func(client bluetooth.Connection, offset int, value []byte) {
					fmt.Print("value: ", string(value))
					if string(currentServer) == "Input Command: " || string(currentServer) == "Authenticated! Input Command: " || string(currentServer) == "Failed! Input Command: " || string(currentServer) == "Reboot request received. Input Command: " || string(currentServer) == "Wifi established! Input Command: " {
						if string(value) == "exit" {
							panic("exit")
						}
						if string(value) == "reboot" {
							_, err = serverCharacteristic.Write([]byte("Reboot request received"))
							currentServer = []byte("Reboot request received. Input Command: ")
							if err != nil {
								panic("failed to write: " + err.Error())
							}
							_, err := exec.Command("/bin/sh", "-c", "sudo reboot now").Output()
							if err != nil {
								panic("failed to reboot: " + err.Error())
							}
						}
						if string(value) == "authenticate" {
							_, err = serverCharacteristic.Write([]byte("Authenticate: "))
							currentServer = []byte("Authenticate: ")
							if err != nil {
								panic("failed to write: " + err.Error())
							}
						}
...
@aykevl
Copy link
Member

aykevl commented Jan 3, 2024

Is this on Linux?
It would help if you can make a small self-contained test case, so I can debug the issue myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants