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

Neo Coolcam PIR Coprocessor Support #306

Closed
Styx85 opened this issue Jan 7, 2019 · 140 comments
Closed

Neo Coolcam PIR Coprocessor Support #306

Styx85 opened this issue Jan 7, 2019 · 140 comments

Comments

@Styx85
Copy link

Styx85 commented Jan 7, 2019

I recently ordered one of these NEO Coolcam PIR WIFI sensors .

The PIR itself is quite handy and small (sized like a golf ball).
When you take it apart you find a ESP8266EX and a lot of pinholes to connect to. Have a look at forum diskussion here.

The standard software is placed in the tuya/smart life universe and the PIR supports IFTT. Some sellers mention amazon alexa and google home support, but that is not integrated (yet?).

The original behaviour of the PIR is to detect movement, give a signal with the integrated LED's when movement is detected and return to deep sleep if there isn't any movement for 60 seconds.

4368035362b95e46186e38308e7acf5dc6cb7707

when connecting the marked pins it is possible to flash the pir and extract the original firmware.
the esphomeyaml I created so far looks like this:

esphomeyaml:
  name: pir2
  platform: ESP8266
  board: esp01_1m
  board_flash_mode: dout

wifi:
  ssid: MyHomeNetwork
  password: VerySafePassword
  domain .veryowndomain

mqtt:
  broker: ip
  username: user
  password: MyMQTTPassword

logger:
  level: VERY_VERBOSE
debug:

ota:
  password: passwd

binary_sensor:
  - platform: gpio
    pin: 
#      number: GPIO1
#      number: GPIO2
#      number: GPIO3
#      number: GPIO4
#      number: GPIO5
#      number: GPIO12
#      number: GPIO13
#      number: GPIO14
#      number: GPIO15
    name: "esp_xxx_pir"
    device_class: motion
 ## https://esphomelib.com/esphomeyaml/components/binary_sensor/status.html
  - platform: status
    name: "esp_xxx_pir_system_status"
    id: "esp_xxx_pir_system_status"

sensor:
  ## https://esphomelib.com/esphomeyaml/components/sensor/uptime.html
  - platform: uptime
    name: "esp_xxx_pir_system_uptime"
    id: esp_xxx_pir_system_uptime

  ## https://esphomelib.com/esphomeyaml/components/sensor/wifi_signal.html
  - platform: wifi_signal
    name: "esp_xxx_pir_system_wifi_signal"
    id: esp_xxx_pir_system_wifi_signal
    update_interval: 15s

With that configuration boot-up is working, mqtt is working wifi-OTA is working.
So far none of the GPIO's was sucessful in keeping it alive or sending a signal. Exactly after 60 seconds the PIR is dead and has to be repowered manually.
So I think I have to figure out how to get the signal after deep sleep wake-up (that has to happen without programming I think).

Would it be wise to set the GPIO's to OUTPUT mode?
Any ideas how to procede?

@OttoWinter
Copy link
Member

So far none of the GPIO's was sucessful in keeping it alive or sending a signal.

What do you mean by that? Also, from the config it looks like you haven't tried pin 16 yet. The PIR sensor is pretty likely connected to pin 16 as that's the pin that supports waking from deep sleep.

Exactly after 60 seconds the PIR is dead and has to be repowered manually.

So the ESP crashes after exactly 60 seconds? That's weird.

Would it be wise to set the GPIO's to OUTPUT mode?

No

@brandond
Copy link
Collaborator

brandond commented Jan 8, 2019

Also, I don't think there's any great support for deep sleep at the moment, is there? As far as esphomelib is concerned, it's just another powerup; the only difference is the reset reason, right?

Also, iirc GPIO16 has to be wired up to the reset pin in order to be used as a wakeup timer, right? All it does is pull GPIO16 low when the deep sleep time expires, at which point the system powers up again with all memory reset as if from a cold boot.

There are other low-power modes available that keep memory and wifi available, but they're not likely to get you the power efficiency you're looking for on a battery powered unit like that.

@OttoWinter
Copy link
Member

Also, I don't think there's any great support for deep sleep at the moment, is there? As far as esphomelib is concerned, it's just another powerup; the only difference is the reset reason, right?

https://esphomelib.com/esphomeyaml/components/deep_sleep.html

Also, iirc GPIO16 has to be wired up to the reset pin in order to be used as a wakeup timer, right?

That's if you want to it in wakeup "timer" mode. But I think in this case the product is designed in such a way that the RST pin is pulled high by the PIR directly, so the ESP will boot up exactly when the PIR sensor activates.

at which point the system powers up again with all memory reset as if from a cold boot.

except for RTC memory, which esphomelib uses as a store for all of its persistent data with ESP8266s. But I think for this application persistent data isn't required anyway?

@brandond
Copy link
Collaborator

brandond commented Jan 8, 2019

By 'great support' I meant there wasn't any special handling for deepsleep wakeup. The sleep itself is definitely well supported - but when it boots it still has to go through the whole init, associate, dhcp, connect to mqtt, etc process as if it were a cold boot. There are no shortcuts or speedups. Any handling of determining a sensor wakeup vs timer wakeup would need to be done manually, correct?

@Styx85
Copy link
Author

Styx85 commented Jan 8, 2019

So far none of the GPIO's was sucessful in keeping it alive or sending a signal.

What do you mean by that? Also, from the config it looks like you haven't tried pin 16 yet. The PIR sensor is pretty likely connected to pin 16 as that's the pin that supports waking from deep sleep.

I forgot GPIO16, true. I believed like @brandond that it was connected to the reset pin and just doing its magic and I just have to fetch some output signal tu use it in HA

Exactly after 60 seconds the PIR is dead and has to be repowered manually.

So the ESP crashes after exactly 60 seconds? That's weird.

no it doesn't crash. It's the standard behaviour of the PIR and it seems it is realized in hardware that it goes into deepsleep after 60 seconds. if you put your ear next to the board it's probably realized with some electric coil or inductor.

Would it be wise to set the GPIO's to OUTPUT mode?

No
straight answers.
thanks very much, I'll tinker a little more and report what I found.

@Styx85
Copy link
Author

Styx85 commented Jan 8, 2019

By 'great support' I meant there wasn't any special handling for deepsleep wakeup. The sleep itself is definitely well supported - but when it boots it still has to go through the whole init, associate, dhcp, connect to mqtt, etc process as if it were a cold boot. There are no shortcuts or speedups. Any handling of determining a sensor wakeup vs timer wakeup would need to be done manually, correct?

To wait for the boot process is a general problem of the esp module used here. the vendor seems to circumvent the problem in prolonging the PIR signal with some kind of timer or filter.
The process is as follows.After triggering the PIR you get a LED blink after 0.2 seconds. And shortly thereafter a signal in the tuya ap that there is a movement. That could mean that the LED signals the completed boot process and ahortly afterwards a wifi connection is established to transfer the signal.
As with the hardware implemented deep sleep only a sensor wakeup is possible (another guess so far).
I'll try some things and report.

@Styx85
Copy link
Author

Styx85 commented Jan 8, 2019

After the last test GPIO16 itself is also giving no signal, too.
So the circuit must be somewhat different. Maybe like this one described here. I'll test it another time.

@brandond
Copy link
Collaborator

brandond commented Jan 8, 2019

I just ordered one off AliExpress since it seemed like an interesting piece of hardware, and I've been meaning to play with PIR sensors anyway. Won't be here for about a month though :) I've got a logic analyzer so at the very least I should be able to do some tracing on the stock firmware.

@ciscozine
Copy link

I'm interested in this discussione because I have 2 PIR sensors.
Anyone is able to flash with custom firmware?
Thanks

@brandond
Copy link
Collaborator

My device just came in. Haven't got much further than cracking it open and putting a barebones esphomelib firmware on it, which was pleasantly easy to do given the exposed vias.

I have a sneaking suspicion that the secondary MCU controls both the LEDs and the PIR, and the ESP is only woke if some internal threshold is triggered on that side. Other bits of stock functionality like blinking the LEDs at powerup, illumining them when the button is held down, etc all seem to work even with alternate firmware loaded.

If that's the case, there's probably some additional firmware running on there. It seems to persist even if the ESP flash is rewritten, which is good - but we're probably going to have to figure out how to talk to it if we want the chip to get woken up. Hopefully it's as simple as just pulling up a pin at the right time and not a whole complicated serial protocol, although there do appear to be another set of clock and data pins along the edge of the board...

@brandond
Copy link
Collaborator

The pictures don't do this board justice - it's tiny. I've got as far as figuring out that the SB1 'Sleepy Bee' chip is wired up to the external reset pin on the ESP8266. I can confirm that GPIO16 is not wired up to the reset pin, so there's no way for the ESP to wake itself. I can also confirm that the SB1 pulls the external reset pin low after about 110 seconds, so clearly there's some sort of deadline in play. I'm unable to get the unit to wake from motion, so I'm guessing the SB1 is expecting the ESP to do some sort of setup that's not occurring, but I can't find anything else that's wired up between the two chips. I'll keep poking at it, but this is a weird one.

@brandond
Copy link
Collaborator

I managed to kill the ESP core - the SB1 still blinks the LEDs and such but I can't even get the ESP into the bootloader. That's probably the end of my physical exploration of the board - I'll see if I can figure anything out from the flash dump I grabbed, but I'm not optimistic.

Pity, it'd be such a great device if we could just figure out what that other core wanted.

@Styx85
Copy link
Author

Styx85 commented Jan 19, 2019

Real pity you managed to kill it. Or was it only temporary? I thought I killed mine once, then reflashed the original firmware though getting an error but it worked miraculously.
If it's dead I have to figure out by trial and error which Pin of the ESP pulls up the SB1.
Guess the SP1 is resetting the ESP and awaiting kind of an alive signal to keep the ESP alive.
Have you figured out more connections? And true the board is really small and painted with thick white colour. It's not that easy to follow the connections with ones eyes.

@brandond
Copy link
Collaborator

brandond commented Jan 19, 2019

I was messing around with it while powered up and accidentally shorted the external reset pin to 3v3 instead of ground for a couple seconds, after that I can't get anything at all from the ESP - scoping the serial pins shows some output on boot but the timing is all off. Pretty sure I fried something :)

I might try removing the SB1, there are apparently four pads under the corners that I can't hit with a probe. I'm also playing with decompiling the firmware with ScratchABit, but I'm having a hard time figuring out how to load the bits of dumped firmware into the tool and haven't made any meaningful progress.

@brandond
Copy link
Collaborator

Update: I was able to find another set of connections after decapping the SB1.

Using your picture above as a reference, all the via pads above the notch go to the ESP8266, and are labeled intuitively. You can flash firmware over RXD0 and TXD0 by holding GPIO0 to ground as usual. GPIO2 puts out the usual bootloader serial messages at 76923 baud, PLUS a bunch of debug messages from the Tuya firmware. The pads below the notch are for 3v3 and ground, plus another set labeled TDX and RXD. These go to the same pins on the ESP8266 as the RXD0 and TXD0, but on the other side of a pair of resistors. Also on the other side of the resistors are two pins at the top right of the SB1; Multifunction IO P0.4 and P0.5 according to the datasheet. The ESP8266's reset pin is down on the bottom at SB1.5, also connected through a set of resistors. The pins at the far bottom of the board go to the C2 Debug Clock and Data pins on the SB1, which could be interesting if anyone really wanted to get into figuring out what it was doing; it's basically a proprietary bidirectional JTAG protocol.

Interestingly, the board has a 26MHz crystal on it, instead of the more common 40MHz - probably to further reduce battery usage. This might have contributed to my confusion when troubleshooting esphomelib on the board, as there are some things that aren't clocked properly if you compile for the wrong frequency.

Anyways, my board is definitely dead. Knowing what I know now I will probably order another one and see if I can get some logic analyzer traces off the SB1 side of the RXD/TXD pins while running the stock firmware.

Also, the stock firmware seems to run fine on another ESP board I had sitting around. I never actually used the Tuya app to set it up, and I threw away the instructions, so if anyone has any tips on how to use the app to configure it, that might be useful while I wait for the new sensor to come in.

@Styx85
Copy link
Author

Styx85 commented Jan 26, 2019

Interestingly, the board has a 26MHz crystal on it, instead of the more common 40MHz - probably to further reduce battery usage. This might have contributed to my confusion when troubleshooting esphomelib on the board, as there are some things that aren't clocked properly if you compile for the wrong frequency.

So what is the setting I have to set here in esphomeyaml? Or does it only matter for external debugging?

@Styx85
Copy link
Author

Styx85 commented Jan 26, 2019

Also, the stock firmware seems to run fine on another ESP board I had sitting around. I never actually used the Tuya app to set it up, and I threw away the instructions, so if anyone has any tips on how to use the app to configure it, that might be useful while I wait for the new sensor to come in.

using the tuya app is quite easy. you just have to create an account and then add a device. for the pir you have to add "other devices" then it searches for the pir, otherwise its just telling me its not a zwave (guess what...)

@brandond
Copy link
Collaborator

brandond commented Jan 28, 2019

I'm waiting on my replacement devices to get in; in the mean time I've been playing with the PIR firmware flashed to a development board. Unfortunately I can't get the Tuya app to pick it up. After the normal boot messages on GPIO2, it just sits there sending out a fixed sequence on UTX0 at 9600 baud, at alternating 1 second/2 second intervals.
0x55 0xAA 0x00 0x01 0x00 0x00 0x00

I'd love to get it registered with Tuya and see if this changes. At the very least it's something to look for once I get the new devices in.

FWIW, here's the boot log:

ets Jan 8 2013,rst cause:1, boot mode:(3,6)
load 0x40100000, len 1396, room 16 

tail 4
chksum 0x89l
oad 0x3ffe8000, len 776, room 4 

tail 4
chksum 0xe8
load 0x3ffe8308, len 540, room 4 

tail 8
chksum 0xc0
csum 0xc0
2nd boot version : 1.4(b1)
SPI Speed: 40MHz
SPI Mode : QIO
SPI Flash Size & Map: 8Mbit(512KB+512KB)
jump to run user1 @ 1000
OS SDK ver: 1.4.2(23fbe10) compiled @ Sep 22 2016 13:09:03
[notice]user_main.c:267 SDK version:1.4.2(23fbe10)
[notice]user_main.c:271 fireware info name:esp_common_raw_lowper version:1.0.6
[notice]user_main.c:274 tuya sdk compiled at Apr 24 2018 18:13:19
[notice]user_main.c:276 BV:5.20 PV:2.1 LPV:3.1 reset reason: 0epc1=0x00000000, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000,depc=0x00000000
[notice]gw_intf.c:271 Authorization success mode : sta(ec:fa:bc:83:bf:91) add if0 

@Styx85
Copy link
Author

Styx85 commented Jan 28, 2019

That could be the connection sequence, have a look here.

@brandond
Copy link
Collaborator

brandond commented Jan 28, 2019

Oh, tuya-convert is just what I've been looking for. Might save me some soldering in the future.

I might grab my rPi and see if I can get it running on there. Nor sure how the pairing works, but the fact that my AP is dual-band with a 5.8ghz preference and the app says it only supports 2.4gh may be breaking it. Could also be that the firmware is looking for some handshake from the SB1 to go into pairing mode though, since it has no direct connection to the button on the board that's used to put it into that state.

@OttoWinter
Copy link
Member

Same here, awesome work! I'll also close this issue because this is primarily a bug tracker. Discussion can however of course continue here.

@brandond
Copy link
Collaborator

brandond commented Feb 5, 2019

New devices arrived. Was able to capture some useful data going back and forth between the ESP8266 and the SB1 at 9600 bps during complete configuration steps, using both SmartConfig and SoftAP modes. So far I've seen:

# get product key and version from SB1. These match the values embedded in the ESP8266 config memory.
TX: 55 AA 00 01 00 00 00
RX: 55 AA 00 01 00 ${"P":"Okurono2XLVRV0fB","v":"1.1.0"} 19

# status to SB1 - waiting for config (fast blink: SmartConfig mode)
TX: 55 AA 00 02 00 01 00 02
RX: 55 AA 00 02 00 00 01

# status to SB1 - waiting for config (slow blink: SoftAP mode)
TX: 55 AA 00 02 00 01 01 03
RX: 55 AA 00 02 00 00 01

# status to SB1 - wifi up, no IP
TX: 55 AA 00 02 00 01 02 04
RX: 55 AA 00 02 00 00 01

# status to SB1 - wifi up, IP up, no MQTT
TX: 55 AA 00 02 00 01 03 05
RX: 55 AA 00 02 00 00 01

# status to SB1 - wifi up, IP up, MQTT up
TX: 55 AA 00 02 00 01 04 06
RX: 55 AA 00 02 00 00 01

# holding down button; reset command from SB1 with delayed ack from ESP
RX: 55 AA 00 03 00 00 02
TX: 55 AA 00 03 00 00 02

# Motion event from SB1 with delayed success ack from ESP
RX: 55 AA 00 05 00 05 65 01 00 01 00 70
TX: 55 AA 00 05 00 01 00 05

The product ID and version check always happen first, followed by status updates as the device brings up the network stack. The ESP8266 will stay online for about two minutes waiting to connect or be configured. If the ESP8266 sends an all-clear message (wifi up, IP up, MQTT up), it will get powered down about 3.5 seconds later if the SB1 has nothing for it to do. If the SB1 has a motion event, the response to the all-clear will be immediately followed by a motion event sequence. The ESP is powered down immediately after acking the motion event.

A summary of the boot process (with both traffic between the ESP and SB1, and log messages) is here: https://gist.github.com/brandond/9c88b9ca204ec3152b8078c47db4c484

@Styx85
Copy link
Author

Styx85 commented Feb 8, 2019

This is great work.
But I actually don't know yet what it means to us to get it work with epshomelib. You got any idea?

@brandond
Copy link
Collaborator

brandond commented Feb 9, 2019

I should be able to write a pretty basic UART component to talk to the SB1, but first we need to move the standard serial logging output to GPIO2 to free up GPIO1 and GPIO3. I'll probably put in a PR to allow for setting an option in the logger component to do that, unless @OttoWinter has a different preference.

Once that's done, I'll put together a UART component to talk to the SB1. That would include:

  • sending status messages during the boot / OTA process to prevent early sleep
  • acking the reset / motion messages to allow the system to go back to sleep as quickly as possible
  • sending an update via API / MQTT when a motion event is triggered

@Styx85
Copy link
Author

Styx85 commented Feb 10, 2019

That would be gorgeous. I'm happily testing it when its done. Unfortunately programming itself is not one of my skills.

@mplinuxgeek
Copy link

I ordered one of these a few weeks ago (arriving today) hoping to "decloud" it with tuya-convert but obviously the SB1 throws a spanner in the works, I'm happy to offer what ever help or testing I can, please hit me up if theres something I can do to help. I've now had intruders in my backyard twice in a month and wanted to deploy at least 4 of these!

After reading this I'd be fairly confident that I could wire the "motion" LED to a GPIO and GPIO16 to RST to bypass the SB1... thoughts?

@brandond
Copy link
Collaborator

The traces on this thing are tiny, I would not plan on rewiring anything. The LEDs are controlled by the SB1, and flash in predetermined patterns - slow blink when configuring in AP mode, fast blink when configuring via SmartConfig, long blink when motion detected followed by a single short blink when the motion has been transmitted to the server, etc. All of this is coordinated by the status messages send back and forth via the UART.

@brandond
Copy link
Collaborator

If you wanted a challenge, you could dump out the flash on the SB1 and reprogram that thing, though. Then you could do whatever you wanted with the LEDs and power state on the ESP.

@ciscozine
Copy link

Hi @brandond, I push the button to enable fast-blinking and I launch the OTA update but after it fail.
The signal is strength (I use a professional Cisco access point).

concerning the second question, into the pir.yaml file I have set the log level to 'info' but if I analyze the mqtt message send to my broker, I see a debug mqtt message.

thanks

@brandond
Copy link
Collaborator

What do the MQTT logs say while you're doing the OTA update? If it's not timing out there should at least be progress messages.

All logs sent via MQTT go to the 'name/debug' topic regardless of their severity, That's just the default log topic, you can change it if you don't like it. Reducing the log level actually compiles out messages of a higher level, so (for example) at INFO level the firmware will not contain any DEBUG or VERBOSE level messages.

@ciscozine
Copy link

Hi, to flash via USB I use GND and V (3.3) Pin.
These are the messages that the mqtt broker receive:

[0;33m[W][ota:420]: Timeout waiting for data![0m
[0;33m[W][ota:386]: Update end failed! Error: ERROR[0]: No Error[0m
[0;32m[I][helpers:266]: Rebooting safely... Reason: 'sb1-ota-timeout'[0m

Thanks

@brandond
Copy link
Collaborator

brandond commented Mar 12, 2019

OK, so it's not rebooting prematurely or anything else weird like that, just a plain network communication issue. Are you able to successfully OTA update any other devices? Have you tried using another host to send the OTA?

@ciscozine
Copy link

ciscozine commented Mar 12, 2019

I have two PIR and each one has the same problem. I use OTA with other esp8266 devices without problem
I find the solution. I need to put the PIR near to the access-point. I don't know why but I have resolved.

Thanks

@ciscozine
Copy link

door

Regarding the door sensor, I have bouth it
image

image

I used the gpi0, 3.3v, gnd, txd0 and rxd0 without good result. have you flashed your door sensor? is it the same?

Unfortunately, the gpi0 pin (on the up-left) has you can see in the photo is damaged.. any suggestions?

thanks

@brandond
Copy link
Collaborator

brandond commented Mar 13, 2019

I haven't flashed mine yet; I have been doing some captures off the stock firmware so I can make sure I document it properly. I don't usually solder on to these though, as the components are so fine; instead I try to get them going with a set of clip or pincer probes from my logic analyzer. It looks identical to yours, except all the pads are in good shape.

If that GPIO0 pad is really hosed, you might see if you can get tuya-convert working. You'll need to have an esphome firmware ready to go, and replace the tasmota binary that comes with it.

@LouiS22
Copy link

LouiS22 commented Mar 13, 2019

I haven't flashed mine yet; I have been doing some captures off the stock firmware so I can make sure I document it properly. I don't usually solder on to these though, as the components are so fine; instead I try to get them going with a set of clip or pincer probes from my logic analyzer. It looks identical to yours, except all the pads are in good shape.

If that GPIO0 pad is really hosed, you might see if you can get tuya-convert working. You'll need to have an esphome firmware ready to go, and replace the tasmota binary that comes with it.

I've tried to get it updated with tuya-convert, unsuccessfully. Might try again as I have a feeling that it's because the timing issue you mentioned before.

@mplinuxgeek
Copy link

mplinuxgeek commented Mar 13, 2019

@ciscozine the below pinout shows you where GPIO is on the ESP8266EX chip, its pin 15. I was hoping the resistor close by that side of the chip may be connected to GPIO0 but its not. You may be able to get it to boot by using a sewing needle/pin to ground it but you may need 2 pairs of hands to get it all done.

ESP8266-EX-PINOUTS

@ciscozine
Copy link

@mplinuxgeek Thanks!
@brandond with type of clip or pincer probes do you use? the pin are so close. I have tested with tuya convert without good result (ct-Open-Source/tuya-convert#135)

thanks

@CopyCat73
Copy link

Tuya convert doesn't seem to be working because the pir goes back to sleep once the connection is established.. which is strange because I would imagine it can stay awake during a normal ota upgrade. Is there a way to send the initial firmware from brandond to it when it is in the slow flashing AP mode? I also can't seem to flash it using the pins.

@ciscozine
Copy link

I hope my question is not offtopic; have you got suggestion for a door sensor managed via mqtt? Thanks

@mplinuxgeek
Copy link

I hope my question is not offtopic; have you got suggestion for a door sensor managed via mqtt? Thanks

I don't plan on continuing with these wifi motion and PIR sensors, they were a cool toy but don't respond fast enough for me, I have purchased a CC2531 and flashed it with Z Stack to use as a generic zigbee2mqtt gateway and have started with some Xiaomi Zigbee sensors.

@brandond
Copy link
Collaborator

There's about a 3 second delay before the event hits MQTT, which is fine for me. Unfortunately the limited battery life makes them unsuitable for high traffic areas. I think I might like the door sensor more than the PIR, just because I suspect it will last longer.

@mplinuxgeek
Copy link

@brandond I'm finding anywhere from 3 to 10 seconds and they often don't capture motion, I am using one to trigger lights at my front door and it often completely fails to trigger.

@brandond
Copy link
Collaborator

Some of mine seem to get stuck after a while and stop detecting until I reset them, while others have been running fine for weeks. They're all within 20 feet of my AP so I don't think it's a signal issue, and I have no reason to think that the code that interacts with the SB1 is at fault... but I didn't run them with the stock firmware long enough to see if they have the same issues with different code on the ESP.

@CopyCat73
Copy link

I still can't even manage to flash them.. I have three and they all time out on the flash procedure. I've been at it for days and can't figure out what's wrong. Tried all sorts of power supplies.

@TSparkas
Copy link

Giving up for the moment. All other ESP8266 devices I have connect without issues to TTL adapter, but not this PIR, not sure where is the problem. I have 2 devices, the same issue on both.

Finally managed to flash both units with CP2102 USB to TTL adapter. FTDI232 adapter was not working. Hopefully will help someone.

@CopyCat73
Copy link

Giving up for the moment. All other ESP8266 devices I have connect without issues to TTL adapter, but not this PIR, not sure where is the problem. I have 2 devices, the same issue on both.

Finally managed to flash both units with CP2102 USB to TTL adapter. FTDI232 adapter was not working. Hopefully will help someone.

Great news.. CP2102 is on order :) I'm wondering what the most efficient way would be to disconnect the SB1; I'd like to hook the pir up to a permanent power source, hopefully that would make it more reliable but I would need to stop the SB1 from powering down the board.

@CopyCat73
Copy link

So these things barely last 3 days on brandond's firmware without getting confused and becoming unresponsive. I have them hooked up to a 3.3v adapter, no need to save battery. I would like to prevent the coprocessor from pulling the reset and keeping the board alive. I could probably do that in a physical way by removing the connection, or making sure the coprocessor does not get the final mqtt ack? Not sure how to approach either of those solutions, could anyone advise?

@TSparkas
Copy link

For me it's working stable for almost a month now, on battery though :)

@mplinuxgeek
Copy link

I could probably do that in a physical way by removing the connection, or making sure the coprocessor does not get the final mqtt ack? Not sure how to approach either of those solutions, could anyone advise?
It should just be a matter of cutting the trace to pin 32 on the ESP, or possibly completely removing the SB1 chip from the board, there will be no right or wrong way to do this, just varying levels of destruction.

Brandons code will no longer work, you'll have to treat this board like a ESP8266 after and chances are the modification will be irreversible.

You would be better off looking at alternate products like Xiaomi motion sensors with a CC2531 USB dongle.

@brandond
Copy link
Collaborator

brandond commented May 3, 2019

You'd have to completely rewire the thing if you cut out the coprocessor. The ESP doesn't do anything except handle external connectivity - the PIR and Reed sensors (on the door sensor) are all wired into the SB1.

@LouiS22
Copy link

LouiS22 commented May 4, 2019

Bit offtopic, but Is there anyone willing to solder and flash a door sensor for me? I've ruined two pieces now and was unable to solder it (my hands are too shaky)? I'm willing to pay the sensor, the postage and the fee of the soldering/flashing. Reason: the place I want to use the sensor has only wifi coverage (from an access point), but no power outlets, etc that's why I'm forced to use wifi door sensor.

@mplinuxgeek
Copy link

mplinuxgeek commented May 4, 2019

@LouiS22 if you can't modify them yourself consider Zigbee instead, a CC2531 USB dongle and either a Xiaomi motion or IKEA motion sensor would be suitable alternatives and don't require power outlets.

See https://www.zigbee2mqtt.io for more info.

@brandond
Copy link
Collaborator

FYI for anyone still following this thread - I've just updated the code to work with 1.13, and confirmed that it works great with Arduino framework 1.5.1. Door sensors should also be working.

@BestEnemies
Copy link

This is great, thanks @brandond . Before I found this thread I found https://docs.tuya.com/en/mcu/mcu-protocol.html - it looks to be documentation of the serial protocol, you likely have found it but didnt see mention on this thread.

@brandond
Copy link
Collaborator

brandond commented Jun 4, 2019

That's awesome @BestEnemies, I'd not turned that up. Having access to that doc might help me fix some of the lingering issues I've had with the reverse engineered protocol. It's simple enough that I was able to get it working on my own, but I didn't quite know for sure what some of the messages meant. Occasionally I've of my devices (not the same one, just one at random) will drop off the network until I reset it; I'm not sure if it's the device, my code, or the framework that's to blame.

@brandond
Copy link
Collaborator

brandond commented Jun 5, 2019

@BestEnemies I finally got a chance to look through that protocol spec page. It seems to document a different version of the protocol than these devices are using - in particular all the examples show the MCU sending version 3 messages, while the version field sent by all the devices I've used is set to 0.

Critically, the command word values used are different, as are some of the payloads for the common command words.

v0 CW v3 CW Description
N/A 0x00 Heartbeat detection.
0x01 0x01 Query product information.
N/A 0x02 Query the working mode of the Wi-Fi module.
0x02 0x03 Report the network connection status of the device.
0x03 0x04 Reset the Wi-Fi module and switch the network configuration mode.
N/A 0x05 Reset the Wi-Fi module and select a network configuration mode.
N/A 0x06 Deliver DP commands.
0x05 0x07 Report DP status.
N/A 0x08 Query the device initialization status.
N/A 0x0a (Optional) Start OTA upgrade.
N/A 0x0b (Optional) Transmit the OTA upgrade package.
N/A 0x1c (Optional) Obtain the local time.
N/A 0x0e Test the Wi-Fi function (product testing command).

@esphome esphome locked and limited conversation to collaborators Jun 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants