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

installed, seems to run but no final stage #2

Open
mssmison opened this issue Jan 15, 2019 · 13 comments
Open

installed, seems to run but no final stage #2

mssmison opened this issue Jan 15, 2019 · 13 comments

Comments

@mssmison
Copy link

mssmison commented Jan 15, 2019

I think I got everything figured out tonight. I had mosquitto running already which was causing this to crash.
Now after that things are looking promising:

Configuration file: /tmp/create_ap.wlan0.conf.kGk16Svp/hostapd.conf
Failed to create interface mon.wlan0: -95 (Operation not supported)
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr b8:27:eb:ab:4a:16 and ssid "tuya_mdev_test"
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
[INFO] [1/14/2019, 7:21:24 PM] MockTuyaCloud: prompting unlinked devices to connect to the network
[INFO] [1/14/2019, 7:21:24 PM] MockTuyaApi: server started on 192.168.12.1 port 80
[INFO] [1/14/2019, 7:21:25 PM] MockTuyaCloud: found device 57074320807d3a3aceba at 192.168.1.10
[INFO] [1/14/2019, 7:21:25 PM] MockTuyaCloud: moving 57074320807d3a3aceba to tuya_mdev_test

and then it found ALL of my tuya devices: then

wlan0: STA 80:7d:3a:3a:ce:ba IEEE 802.11: associated
wlan0: AP-STA-CONNECTED 80:7d:3a:3a:ce:ba
wlan0: STA 80:7d:3a:3a:ce:ba RADIUS: starting accounting session 5C3D5FBE-00000000
wlan0: STA 80:7d:3a:3a:ce:ba WPA: pairwise key handshake completed (WPA)
wlan0: STA 80:7d:3a:3a:ce:ba WPA: group key handshake completed (WPA)

After going through that with all of my devices:

wlan0: STA 80:7d:3a:3a:ce:ba IEEE 802.11: disassociated
wlan0: AP-STA-DISCONNECTED 80:7d:3a:3a:ce:ba
wlan0: STA 80:7d:3a:3a:ce:ba IEEE 802.11: disassociated

and then it loops back through the second section again. I panicked a little wondering if I had to reset up all of my lights but when I quit nothing had changed with the bulbs at all and there was no final stage AP's

Is it best to use a non-setup light?

@mssmison
Copy link
Author

mssmison commented Jan 15, 2019

Looking a bit further and all of these lights are no showing as offline in the app except for three.
I can see they're connected to my wifi though. I'll try resetting them up.

confirmed put the bulbs back in pairing mode and the app re-added them as the same devices. Phew!
I tried with just one bulb that was in pairing mode when I started the script but there's no indication that it finds it and

@kueblc
Copy link
Owner

kueblc commented Jan 15, 2019

Thanks so much for the detailed report.

I think I got everything figured out tonight. I had mosquitto running already which was causing this to crash.

I hadn't considered people might already be running an MQTT broker on the same machine, what I could do is detect that situation and connect as a client instead of spinning up Mosca.

wlan0: STA 80:7d:3a:3a:ce:ba IEEE 802.11: associated
wlan0: AP-STA-CONNECTED 80:7d:3a:3a:ce:ba
wlan0: STA 80:7d:3a:3a:ce:ba RADIUS: starting accounting session 5C3D5FBE-00000000
wlan0: STA 80:7d:3a:3a:ce:ba WPA: pairwise key handshake completed (WPA)
wlan0: STA 80:7d:3a:3a:ce:ba WPA: group key handshake completed (WPA)

After going through that with all of my devices:

wlan0: STA 80:7d:3a:3a:ce:ba IEEE 802.11: disassociated
wlan0: AP-STA-DISCONNECTED 80:7d:3a:3a:ce:ba
wlan0: STA 80:7d:3a:3a:ce:ba IEEE 802.11: disassociated

This output is from the create_ap script, looks like it successfully connected to the devices but then they disconnected for some reason. I was having similar issues at one point, let me see if I can reproduce that today.

I'm assuming there wasn't any output between reported from MockTuyaApi? Should have had output showing the devices requesting upgrades at this point.

Is it best to use a non-setup light?

Shouldn't make too much of a difference.

With an unlinked device, the mock cloud will issue its own keys and so will be able to fully decrypt messages from the device. If you have keys for your existing devices, you can add them to device-info.js and you'll get the same effect. But either way, for the purpose of firmware upgrades you don't need to know any encryption keys.

confirmed put the bulbs back in pairing mode and the app re-added them as the same devices

Glad you were able to recover your devices. It's likely that they were still trying to connect to the mock AP. I could add a recovery script to move the devices back to your regular network if the process fails or user cancels.

I tried with just one bulb that was in pairing mode when I started the script but there's no indication that it finds it and

Did the device in pairing mode stop blinking? I'm assuming you did not see any output from MockTuyaApi

@mssmison
Copy link
Author

I'm assuming there wasn't any output between reported from MockTuyaApi? Should have had output showing the devices requesting upgrades at this point.

That's correct it just kept looping between connecting and disconnecting.

Did the device in pairing mode stop blinking? I'm assuming you did not see any output from MockTuyaApi

No it didn't seem to find that device at all. Per your comment on the other issue:

I have discovered in testing today that some devices simply do not request a silent upgrade on start up and need to be prompted to do so from MQTT using protocol 15. This would explain why some devices seem to stall on the s.gw.dev.timer.count API call.

I think my devices (bulbs) are examples of this and wonder if that's why nothing was happening with your script after they connected?

@kueblc
Copy link
Owner

kueblc commented Jan 15, 2019

Thanks again for your time and patience, your input is really valuable for proofing this software.

I think my devices (bulbs) are examples of this and wonder if that's why nothing was happening with your script after they connected?

Very well may be, but you should still see some output from MockTuyaApi, such as some calls to s.gw.dev.timer.count etc, so I believe the blocking issue here is with maintaining connection to our mock AP. Once we can establish that your device is connecting to the mock AP, we can add a routine to the script that sends the MQTT upgrade command.

I've got some time tonight so I'm going to try incorporating all this new information and automating more of the workflow.

@mssmison
Copy link
Author

Awesome.
Thanks for your time.

@kueblc
Copy link
Owner

kueblc commented Jan 18, 2019

If you'd like to try again, I've added an MQTT upgrade command to the routine. I was able to get some stubborn devices to finally flash using this. I believe this should fix the issue folks have been having with stalling on "s.gw.dev.timer.count" etc. Note that you will need the device's secKey and localKey added to lib/config.js OR put the device in pairing mode and allow the mock cloud to link and issue it's own keys.

As far as maintaining connect to the mock AP, I believe the issue could be DNS related. If the device was already online before the script runs, it may have already resolved to the real API endpoint. In theory I should be able to catch all outgoing requests but for now I'm only intercepting calls to the .tuya.com domains. As a temporary workaround you might try power cycling the device to force it to resolve again, OR by putting the device in pairing mode to initialize from scratch.

@mssmison
Copy link
Author

Great! I try and give this a go tonight and let you know!

@mssmison
Copy link
Author

Just looking at the config.js file, do I just replace the defaultSecKey and defaultLocalKey with the ones for the device?

@kueblc
Copy link
Owner

kueblc commented Jan 18, 2019

That's my mistake, I forgot to update the example config. I just pushed an updated example, you can add the devices' keys as a map with the device's gwId as the key and the encryption key as the value.

@kueblc
Copy link
Owner

kueblc commented Jan 18, 2019

However if it's just one device, there's no harm in putting the keys in defaultSecKey and defaultLocalKey

@mssmison
Copy link
Author

I tried tonight two different approaches tonight.
With a bulb set on pairing mode it just kept flashing and never found anything.

pi@raspberrypi:~/mocktuyacloud $ ./ota-firmware.sh
Creating network at tuya_mdev_test
WARN: brmfmac driver doesn't work properly with virtual interfaces and
      it can cause kernel panic. For this reason we disallow virtual
      interfaces for your adapter.
      For more info: https://github.com/oblique/create_ap/issues/203
WARN: Your adapter does not fully support AP virtual interface, enabling --no-virt
Config dir: /tmp/create_ap.wlan0.conf.EAc4HxqD
PID: 4323
Network Manager found, set wlan0 as unmanaged device... DONE
No Internet sharing
hostapd command-line interface: hostapd_cli -p /tmp/create_ap.wlan0.conf.EAc4HxqD/hostapd_ctrl
Configuration file: /tmp/create_ap.wlan0.conf.EAc4HxqD/hostapd.conf
Failed to create interface mon.wlan0: -95 (Operation not supported)
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr b8:27:eb:ab:4a:16 and ssid "tuya_mdev_test"
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
[INFO] [1/19/2019, 5:06:52 PM] MockTuyaApi: server started on 192.168.12.1 port 80
[INFO] [1/19/2019, 5:06:52 PM] MockTuyaMQTT: mqtt started on 192.168.12.1 port 1883
[INFO] [1/19/2019, 5:06:57 PM] MockTuyaCloud: prompting unlinked devices to connect to the network
[DEBUG] [1/19/2019, 5:06:57 PM] TuyaLink: Sending SmartLink initialization packets
[DEBUG] [1/19/2019, 5:06:59 PM] TuyaLink: Sending SmartLink data packets
[DEBUG] [1/19/2019, 5:07:02 PM] TuyaLink: Finished sending packets.
[INFO] [1/19/2019, 5:07:07 PM] MockTuyaCloud: prompting unlinked devices to connect to the network
[DEBUG] [1/19/2019, 5:07:07 PM] TuyaLink: Sending SmartLink initialization packets
[DEBUG] [1/19/2019, 5:07:09 PM] TuyaLink: Sending SmartLink data packets
[DEBUG] [1/19/2019, 5:07:13 PM] TuyaLink: Finished sending packets.'

With a bulb that was already paired after entering the keys. I ran the script and the bulb did flash briefly but nothing else seemed to happen. Afterwards, as before I had to re-initialize the bulb in the tuya app.

'pi@raspberrypi:~/mocktuyacloud $ ./ota-firmware.sh
Creating network at tuya_mdev_test
WARN: brmfmac driver doesn't work properly with virtual interfaces and
      it can cause kernel panic. For this reason we disallow virtual
      interfaces for your adapter.
      For more info: https://github.com/oblique/create_ap/issues/203
WARN: Your adapter does not fully support AP virtual interface, enabling --no-virt
Config dir: /tmp/create_ap.wlan0.conf.pj5wCc6f
PID: 6103
Network Manager found, set wlan0 as unmanaged device... DONE
No Internet sharing
hostapd command-line interface: hostapd_cli -p /tmp/create_ap.wlan0.conf.pj5wCc6f/hostapd_ctrl
Configuration file: /tmp/create_ap.wlan0.conf.pj5wCc6f/hostapd.conf
Failed to create interface mon.wlan0: -95 (Operation not supported)
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr b8:27:eb:ab:4a:16 and ssid "tuya_mdev_test"
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED
[INFO] [1/19/2019, 5:16:51 PM] MockTuyaApi: server started on 192.168.12.1 port 80
[INFO] [1/19/2019, 5:16:52 PM] MockTuyaMQTT: mqtt started on 192.168.12.1 port 1883
[INFO] [1/19/2019, 5:16:54 PM] MockTuyaCloud: found device 57074320807d3a3aceba at 192.168.1.10
[INFO] [1/19/2019, 5:16:54 PM] MockTuyaCloud: moving 57074320807d3a3aceba to tuya_mdev_test
[INFO] [1/19/2019, 5:16:56 PM] MockTuyaCloud: prompting unlinked devices to connect to the network
[DEBUG] [1/19/2019, 5:16:56 PM] TuyaLink: Sending SmartLink initialization packets
wlan0: STA 80:7d:3a:3a:ce:ba IEEE 802.11: associated
wlan0: AP-STA-CONNECTED 80:7d:3a:3a:ce:ba
wlan0: STA 80:7d:3a:3a:ce:ba RADIUS: starting accounting session 5C43DA10-00000000
wlan0: STA 80:7d:3a:3a:ce:ba WPA: pairwise key handshake completed (WPA)
wlan0: STA 80:7d:3a:3a:ce:ba WPA: group key handshake completed (WPA)
[DEBUG] [1/19/2019, 5:16:58 PM] TuyaLink: Sending SmartLink data packets
[DEBUG] [1/19/2019, 5:17:02 PM] TuyaLink: Finished sending packets.
[INFO] [1/19/2019, 5:17:07 PM] MockTuyaCloud: prompting unlinked devices to connect to the network
[DEBUG] [1/19/2019, 5:17:07 PM] TuyaLink: Sending SmartLink initialization packets
[DEBUG] [1/19/2019, 5:17:09 PM] TuyaLink: Sending SmartLink data packets
[DEBUG] [1/19/2019, 5:17:13 PM] TuyaLink: Finished sending packets.
[INFO] [1/19/2019, 5:17:18 PM] MockTuyaCloud: prompting unlinked devices to connect to the network
[DEBUG] [1/19/2019, 5:17:18 PM] TuyaLink: Sending SmartLink initialization packets
[DEBUG] [1/19/2019, 5:17:19 PM] TuyaLink: Sending SmartLink data packets
[DEBUG] [1/19/2019, 5:17:23 PM] TuyaLink: Finished sending packets.
[INFO] [1/19/2019, 5:17:28 PM] MockTuyaCloud: prompting unlinked devices to connect to the network
[DEBUG] [1/19/2019, 5:17:28 PM] TuyaLink: Sending SmartLink initialization packets
[DEBUG] [1/19/2019, 5:17:30 PM] TuyaLink: Sending SmartLink data packets
[DEBUG] [1/19/2019, 5:17:33 PM] TuyaLink: Finished sending packets.
[INFO] [1/19/2019, 5:17:38 PM] MockTuyaCloud: prompting unlinked devices to connect to the network
[DEBUG] [1/19/2019, 5:17:38 PM] TuyaLink: Sending SmartLink initialization packets
[DEBUG] [1/19/2019, 5:17:40 PM] TuyaLink: Sending SmartLink data packets
[DEBUG] [1/19/2019, 5:17:44 PM] TuyaLink: Finished sending packets.
[INFO] [1/19/2019, 5:17:49 PM] MockTuyaCloud: prompting unlinked devices to connect to the network
[DEBUG] [1/19/2019, 5:17:49 PM] TuyaLink: Sending SmartLink initialization packets
[DEBUG] [1/19/2019, 5:17:51 PM] TuyaLink: Sending SmartLink data packets
[DEBUG] [1/19/2019, 5:17:54 PM] TuyaLink: Finished sending packets.
[INFO] [1/19/2019, 5:17:59 PM] MockTuyaCloud: prompting unlinked devices to connect to the network
[DEBUG] [1/19/2019, 5:17:59 PM] TuyaLink: Sending SmartLink initialization packets
wlan0: STA 80:7d:3a:3a:ce:ba IEEE 802.11: disassociated
wlan0: AP-STA-DISCONNECTED 80:7d:3a:3a:ce:ba
wlan0: STA 80:7d:3a:3a:ce:ba IEEE 802.11: associated
wlan0: STA 80:7d:3a:3a:ce:ba IEEE 802.11: disassociated
[DEBUG] [1/19/2019, 5:18:01 PM] TuyaLink: Sending SmartLink data packets
wlan0: STA 80:7d:3a:3a:ce:ba IEEE 802.11: associated
wlan0: AP-STA-CONNECTED 80:7d:3a:3a:ce:ba
wlan0: STA 80:7d:3a:3a:ce:ba RADIUS: starting accounting session 5C43DA10-00000002
wlan0: STA 80:7d:3a:3a:ce:ba WPA: pairwise key handshake completed (WPA)
wlan0: STA 80:7d:3a:3a:ce:ba WPA: group key handshake completed (WPA)
[DEBUG] [1/19/2019, 5:18:04 PM] TuyaLink: Finished sending packets.
[INFO] [1/19/2019, 5:18:09 PM] MockTuyaCloud: prompting unlinked devices to connect to the network
[DEBUG] [1/19/2019, 5:18:09 PM] TuyaLink: Sending SmartLink initialization packets
[DEBUG] [1/19/2019, 5:18:11 PM] TuyaLink: Sending SmartLink data packets
[DEBUG] [1/19/2019, 5:18:14 PM] TuyaLink: Finished sending packets.
[INFO] [1/19/2019, 5:18:19 PM] MockTuyaCloud: prompting unlinked devices to connect to the network
[DEBUG] [1/19/2019, 5:18:19 PM] TuyaLink: Sending SmartLink initialization packets
[DEBUG] [1/19/2019, 5:18:21 PM] TuyaLink: Sending SmartLink data packets
[DEBUG] [1/19/2019, 5:18:25 PM] TuyaLink: Finished sending packets.'

@GeorgeIoak
Copy link

Try running the command as sudo

@kueblc
Copy link
Owner

kueblc commented Jan 20, 2019

Sorry the linking process didn't work for you. It's still pretty flaky, I have to run it a couple times for it to connect for me too. I'm going to be rewriting it soon taking into account new capture data and provide better timing. Tricky as node's event scheduling is not that high resolution or accuracy. Might be easier to extern that to C so I can do a proper usleep without blocking node.

You shouldn't need to run the script with sudo as it uses sudo where necessary already.

Can you confirm that an AP is being generated and you can connect to it with other devices? Try looking for a network while running sudo create_ap -n wlan0 FakeNetwork password. You should be able to connect to it but not access the internet.

If that works, try sudo create_ap -n wlan0 -e <absolute path to tuya_hosts file> FakeNetwork password and see what happens when you ping a.tuyaus.com . It should be 192.168.12.1.

If all that works, I'm thinking that the device has cached the DNS. Did you try power cycling the device after it connected to the mock cloud? This should clear the cache and it will reconnect to the mock AP when it restarts (which is why you might have had to reprovision it in order to use it again).

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

3 participants