nassir-malik / IFTTT-Alexa-And-GoogleHome-Control-Single-Device

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

payload length = 0

GitJer opened this issue · comments

Dear Nassir,

When I issue a voice command, I can see in the Heroku logs that a command is being received and send (with the correct length), and indeed I can see that a message arrives in the ESP8266. But the payload length is 0, and thus I get the "Command is not recognized!" warning. I have followed the instructions in your video, so I am not sure what I am doing wrong. Do you have any ideas what I should check?

To start, when I view the log in Heroku I noticed an error. This may be completely unrelated, but maybe of interest to you:


`Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...

Disconnected from log stream. There may be events happening that you do not see here! Attempting to reconnect...

2017-12-04T20:14:07.373946+00:00 app[web.1]: Traceback (most recent call last):

2017-12-04T20:14:07.373946+00:00 app[web.1]: File "app.py", line 16, in handler

2017-12-04T20:14:07.373947+00:00 app[web.1]: request_line, headers = await websockets.http.read_message(self.reader)

2017-12-04T20:14:07.373947+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/websockets/http.py", line 83, in read_message

2017-12-04T20:14:07.373948+00:00 app[web.1]: start_line = yield from read_line(stream)

2017-12-04T20:14:07.373948+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/websockets/http.py", line 107, in read_line

2017-12-04T20:14:07.373948+00:00 app[web.1]: raise ValueError("Line without CRLF")

2017-12-04T20:14:07.374013+00:00 app[web.1]: ValueError: Line without CRLF

2017-12-04T20:14:58.400250+00:00 app[web.1]: ('Line without CRLF',)`


Anyway, after that Heroku seems to work just fine.

In your esp8266 ino at the top of the 'webSocketEvent' function I have added:


`Serial.println("payload:");

Serial.println((char *)payload);

Serial.println("length:");

Serial.println(length);
`


And near the top of 'processWebScoketRequest', just below the string declarations, I have added:


` Serial.println("printing data and state:");

Serial.println(data);

Serial.println(device);

Serial.println(location);

Serial.println(state);

Serial.println(query);

Serial.println("finished printing data and state");
`


When I first start the esp8266 it gives the following messages:


`payload:
/ws
length:
3
Connected!
payload:
{"event": "OK"}
length:
15

Got data
printing data and state:
{"event": "OK"}

finished printing data and state
Command is not recognized!
Sending response back`


Which, according to one of your videos seems to be good.

When I give my google assistant a voice command I can see in the Heroku log that a message is send with the correct size (it does not show the content of the message). A fraction of a second later my esp8266 serial output gives:


`payload:

length:

0
Got data
printing data and state:

finished printing data and state
Command is not recognized!
Sending response back
`


So, I know that the google assistant (via IFTTT) sends a message to Heroku and that a message arrives at my esp8266, but the content is lost somewhere. I have also added print statements at several locations in WebSockets.cpp, but as far as I can see there the message length is also 0.

See images
ifttt1

ifttt2

Hi Nassir,

Although the original way still does not work, I have copied your code to a local repository and deployed the app on Heroku from there. Now it works!

Thank you for your work and quick response!

Hi nassir-malik. Yes changed time.sleep(.30) works. Thanks a lot.