-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
POST request using ESP32 to Fauxmo works when running Fauxmo with -vvv but not -vv #125
Comments
Sorry you're having trouble. I'm not sure that I understand your question or what is going on.
It sounds like you're describing the intended behavior. There is no difference in behavior based on whether you use |
I understand what you are describing. That's what I expected. When I run in -vv mode I get from the debug output all but the Contents: POST /upnp/control/basicevent1 HTTP/1.1 With no content showing. When I run with -vvv I get Contents. Nothing else changed except going from -vv to -vvv: POST /upnp/control/basicevent1 HTTP/1.1
So as you can see I get the full 298 character content that was sent following the POST...Content-Length section. Nothing changes on the sender side either. So I am guessing maybe the -vvv somehow slows the read of the UDP request enough so it gets the full request with the Contents before moving on. I'm not familiar with the asyncio process and how it effects timing. Thanks for the quick reply! |
I'm sorry, I'm still not sure that I understand what your question is, or what behavior you're seeing that is unexpected. Can you give me an example?
|
Also, you haven't included your config or debug logs as requested, which makes it much harder for me to understand what's going on. |
Thank so much. Trying to get you what I am referring to. First, Fauxmo works fine with Alexa, so that is not an issue. It works as expected. I expect the Fauxmo to respond to an HTTP POST. It works with Curl on Windows and now am trying from a microcontroller. This issue happens when I am trying to get it to respond to a HTTP POST sent from an ESP32 microcontroller. Using "-v" The systemctl output is: The config.json:
I am not sure where to get the debug logs other than the systemctl output and when I run fauxmo manually the outpur from there. |
Interesting. To make sure I understand:
Does this sound correct? If so, that is indeed an odd issue, and I don't have any great ideas.
Out of curiosity, what is your use case for having an ESP32 issue commands to Fauxmo? Is this an intermittent problem? Or does it fail every time without verbose logging and succeed every time with verbose logging?
Yes, your journald output is the next step. |
Yes you understand correctly: all the 3 instances are correct. I am using the Espressif library 3.0.0 (the latest) with HTTPclient POST call. Re Ncat, I' not sure how to do that but can look into it. It's not intermittent - it doesn't work all the time with "-vv", and works all the time with fauxmo "-vvv" Use case: Trying to setup a remote button system to initiate a fauxmo events using the ESP32. I wish there was a more simple REST way to do it since it's all on the same local network. My guess as to the issue: with "-vvv" the UPD read stays open longer but with "-vv" the port closes faster so fauxmo doesn't get the final "data" section of the request. My pyhon for fauxmo is 3.11. I was thinking I could put some sort of delay in the UDP read, but I'm not sure where / how to do that. Same results on debug showing in the journal as the debug. |
Interesting setup. I'm not sure how to help. I don't know what to think about your speculation about the UDP read staying open longer -- I would be surprised to discover that it changed behavior this way, and I don't think that part of the exchange is occurring on UDP. Be sure to review the protocol_notes. There are a few versions of netcat ( I think something like |
Update on sending a POST to Fauxmo: What I tested to see if the POST message comes through: What did not work: Conclusion: |
Interesting, thanks for following up. Can you post your code for the "simple asyncio server"? |
Here is the code:
I also tried the "await" approach using reader.read():
|
Missing a bit -- |
Not sure if you're familiar with wireshark and/or tcpdump, but they might be helpful as well. |
What happens if you add a |
I fixed the code so it has myIP. I was making it generic when I posted the reply and missed that - thanks :) Will try your suggestions. Since netcat gets the whole message, I don't think there is any issues with the message getting to the destination IP. Addendum: I ran my simple test simple server on a Windows machine (much faster than the RPi. Same result - a truncated message. |
Any updates? Were you able to try the |
No success...
|
Could you host a full copy of your ESP32 code for me somewhere? I have a few of them sitting around and may be able to test locally, as I'm not sure how I can help you debug this further remotely. |
Here is a generic version of the code (ZIP file) (needs a SSID, PW and IP/PORT for testing). I used an Adafruit QT Py ESP32 with a neopixel for status. Let me know you got his OK. |
Thanks for the firmware. I've simplified a bit to work on a generic ESP32 and can confirm -- it works intermittently with Curiously the fauxmo logs do not report the message body when it fails:
But include the body when it succeeds:
I'm not sure why that would be. |
Yes, that is the issue. |
By removing all Trying to find documentation on this library is tough. I found for example the |
That's the disconnect error I see too. That is the best doc I could find. I also see it working (mostly) with "-vvv". |
Well, I got totally nerd sniped by this and spent way too much time tinkering with the ESP32 over the last few days. I think I have a probable solution, but I'm not planning to implement it myself at this time as it requires a number of changes and is a niche / unsupported use-case that hasn't presented an issue over the last ~7 years of using Fauxmo. I wanted to lay out my general ideas in case someone wanted to make an attempt at implementing this. It seems that the request from the ESP32 is (usually) getting split into two separate calls to It may be possible to optimize The better / correct way to do this would be to improve Fauxmo's http parsing; it currently doesn't parse things at all, just kind of looks at a request to see if it "seems" like a POST request to turn something on / off (or do something else). If it looks like this is the case, it performs the action and closes the connection. The improvement here would require several changes to the
At least this is the best idea I've had so far. If implemented, I would insist on keeping fauxmo free of external dependencies; python has some stdlib utility classes / functions that would help, such as I'll leave this issue open for a couple weeks to see if there is interest; if not will plan to close as unplanned. |
YAY! I got it to work and there is NO required code change for Fauxmo. This gets around the seemingly two-part send from ESP32 http POST which causes the Python asyncio to close and Fauxmo has no problem receiving the full command. It's a kludge but I'm glad it does not involve anything more than the ESP32 code change. |
Ha! How clever! It's no more of a kludge than fauxmo's "parsing" of the http request. Well done. |
fauxmo --version
): v0.8.0My Issue
I built a request sent via an ESP32 to Fauxmo on my locl network.
The request WORKS when I run Fauxmo in triple V (-vvv) mode but not when I run Fauxmo with two: (-vv)
In more detail the request is recognized in both instances, but the data of the request is not seen with the -vv.
Maybe there is a delay or timing issue?
In -vvv mode Fauxmo read the whole request, but when in -vv the udp read gets stopped?
WHYT
I tried adding more debug "warning" points in protocols.py dumping the "msg" variable.
With "-vvv" I get the whole message as sent with the POST request data.
With "-vv" I get the same headers etc. but not the POST request data.
Please make sure you've taken these steps before submitting a new issue:
venv
-vvv
) and include relevant output (see comments)config.json
(not needed)The text was updated successfully, but these errors were encountered: