Nicnl / homebridge-minimal-http-blinds

GNU General Public License v3.0
12 stars 13 forks source link

Error when polling: status undefined #2

Open crazy-jackrabbit opened 6 years ago

crazy-jackrabbit commented 6 years ago

Hello,

i get this Error and I don´t know how to solve it. I know I have to return the State & Position in Plain Text, but i didn't get it to work. May you can help me?

Error in Homebridge:

[Kitchen Blinds] Error when polling current position: undefined [Kitchen Blinds] Error when polling current state: undefined

Part of my Code (on NodeMCU):

//########## Position ########## server.on("/get/current_position/", [](){ cur_pos_przt = map(cur_pos, pos_min, pos_max, 0, 100); String Position = String(cur_pos_przt); server.send(200, "text/plain", Position); // transfer Blind Position in % to Homekit });

i think this server.send(200, "text/plain", Position); is wrong. But whats right? In my browser server.send is working and returns a number

Nicnl commented 6 years ago

Sorry for responding so late, I'm looking into it

Nicnl commented 6 years ago

I just published version 0.0.16.
It won't fix your issue but the error printing will be a bit more useful than just undefined.

Sorry. I was a bit lazy when writing the error handling and the error text itself wasn't properly printed.

@crazy-jackrabbit could you try again and paste the logs?
It everything goes well, it should be way more precise than before and it'll greatly help us to resolve your issue. Thank you!

crazy-jackrabbit commented 6 years ago

Hello, thank you for your Time. I just updated your Plugin an now i get this in my Log:

Apr 04 17:59:58 hbridge2 homebridge[1676]: [2018-4-4 17:59:58] [Kitchen Blinds] Updated PositionState to value 2 Apr 04 17:59:59 hbridge2 homebridge[1676]: [2018-4-4 17:59:59] [Kitchen Blinds] Updated CurrentPosition and TargetPosition to value 2 Apr 04 17:59:59 hbridge2 homebridge[1676]: [2018-4-4 17:59:59] [Kitchen Blinds] set_target_position is ignoring an actual request... Apr 04 17:59:59 hbridge2 homebridge[1676]: [2018-4-4 17:59:59] [Kitchen Blinds] Updated PositionState to value NaN Apr 04 18:00:00 hbridge2 homebridge[1676]: [2018-4-4 18:00:00] [Kitchen Blinds] Updated CurrentPosition to value 6 Apr 04 18:00:00 hbridge2 homebridge[1676]: [2018-4-4 18:00:00] [Kitchen Blinds] Updated PositionState to value NaN Apr 04 18:00:00 hbridge2 homebridge[1676]: [2018-4-4 18:00:00] [Kitchen Blinds] Updated CurrentPosition to value 2 Apr 04 18:00:00 hbridge2 homebridge[1676]: [2018-4-4 18:00:00] [Kitchen Blinds] Updated PositionState to value NaN

The Valuestate is jumping around. A value between 2-6% is wrong. The Blind is open, so it should be 100%. At the same time, I got another Plugin (homebridge-http-window-covering) running. There it works. But this plugin (homebridge-http-window-covering) isn't updating the State when I change it without it (for example via a Button or website). So I need yours 👍

Nicnl commented 6 years ago

Huh... this is indeed a bit strange.
Is there a way for us to discuss in private? I'd like to investigate a bit more if you don't mind.

crazy-jackrabbit commented 6 years ago

yeah, of course.

Nicnl commented 6 years ago

Hum, I can't get your email on Github.
Send me something at mine.

IgorFX commented 6 years ago

config.json

{
    "name": "Kitchen Blinds",
    "accessory": "MinimalisticHttpBlinds",
    "get_current_position_url": "http://192.168.0.110/position",
    "set_target_position_url": "http://192.168.0.110/set?pers=%position%",
    "get_current_state_url": "http://192.168.0.110/state"
}

code

void handleLogin() 
{
    pers = server.arg("pers");
    int persent = pers.toInt();
    if (persent >= 0 && persent <= 100) 
    { 
        w_state = 2;
        stepper.moveTo(persent*192);
        stepper.run();
        // Serial.print("Position :" + pers);
        server.send(204, "text/plain", server.arg("set"));
    } 
    else
    {
        server.send(401, "text/plain", "401: Wrong Position");   
    }
}

void handlePosition()
{
    stepper.run();
    server.send(200, "text/plain", pers); 
}

Work fine

Nicnl commented 6 years ago

@IgorFX Thank you for your code example.

I'm finding this line quite unusual though:

server.send(204, "text/plain", server.arg("set"));

The HTTP 204 response code is supposed to be No Content.
I'm not sure if that's a good idea to send back data.

Nicnl commented 6 years ago

@IgorFX Since your code works, could you eventually post it entirely?
Adding it to the EXAMPLE.md file would be very helpful to newcomers.
For now it only contains a python example code, but adding an Arduino example would be very appreciated.

IgorFX commented 6 years ago

Sometimes I have Updated PositionState to value NaN When I'm starting Homebridge. But sometimes)

IgorFX commented 6 years ago

https://github.com/Nicnl/homebridge-minimal-http-blinds/blob/a9a95752db22afb847bdbbc5ee55abfc34125fda/examples/IgorFX.ino#L1-L191

I'm use that scetch

Kepete commented 6 years ago

@IgorFX Hei, thank you for your code! I also tried the same code you shared here but I can't get it working. Maybe you can give a brief description how to set it up? I have flashed my NodeMCU with the Arduino IDE and your code. I can open ip and it shows Hello World I can open the site ip/state and it shows 2 If I open the site ip/position it doesn't show anything If I open the site ip/set it shows 404: Not found Homebridge output: Unexpected HTTP status code when polling current position. Got: 404, expected:200

From the code it seems 404: Not found is a problem to connect to the stepper motor. I'm using a 28BYJ-48 stepper with the ULN2003 driver. The driver is working with other scripts and I got the motor rotating. Connected NodeMCU v2 pins like this: D5 -> IN1 D6 -> IN2 D7 -> IN3 D8 -> IN4 Interesting is that when I try to upload from Arduino IDE I get a error: espcomm_open failed when the stepper is connected. If I disconnect it than it upload fine.

How should I be able to set the max position up and max position down? Any help is greatly appreciated

IgorFX commented 6 years ago

Hello Kepete What code in your json file? open the site asip/set?pers=x (x = 0 - 100) global position stepper.setCurrentPosition(0); // Zero Point...If module crash we here

Max position %% from Homebridge * your number of steps the amount is obtained by experience. The height of the window is different for all. and another oddity AccelStepper stepper(HALFSTEP, Pin1, Pin3, Pin2, Pin4); AccelStepper stepper(HALFSTEP, Pin1, Pin3, Pin2, Pin4);

state 2 is the position not of 0 and not of 100. IDLE your position is not set - state 2

IS512 commented 5 years ago

Hi IgorFX

Did you have to modify a json file? I can not find the one applicable. Do you know where it will be located?

dreale1 commented 4 years ago

HI all

I have blinds which works with GET POST http. I have Homebridge installed on a raspberry and now want to steer my blinds via HomeKit using homebridge-minimal-http-blinds

I understand that after installing homebridge-minimal-http-blinds i need to enter following text into the json file:

{ "name": "Kitchen Blinds", "accessory": "MinimalisticHttpBlinds", "get_current_position_url": "http://192.168.0.110/position", "set_target_position_url": "http://192.168.0.110/set?pers=%position%", "get_current_state_url": "http://192.168.0.110/state" }

What don't understand, is where following text needs to be entered:

{ "get_current_position_method": "GET", "set_target_position_method": "POST", "get_current_state_method": "GET",

"get_current_position_expected_response_code": "200",
"set_target_position_expected_response_code": "204",
"get_current_state_expected_response_code": "200",

"get_current_position_polling_millis": "500",
"get_current_state_polling_millis": "500",
"no_cache_duration_millis": "60000"

}

also into the json file? or where else?

pardon my dumb questions but I am not an expert at all... hope you can help me?

the blinds API are attached here 10ZEPAPIE1612.pdf

thanks in advance!!!