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

photon : Comparison between IPAddress objects does not always work #715

Closed
jakeypoo opened this issue Oct 26, 2015 · 3 comments

Comments

@jakeypoo
Copy link
Contributor

commented Oct 26, 2015

Ran into a bug where comparison between a resolved IPAddress is not equal to an IPAddress created using the constructors. Take a look at the test code below :

IPAddress test_x = IPAddress( 192 , 168 , 1 , 142 ) ; 
IPAddress test_y = IPAddress( 192 , 168 , 1 , 142 ) ;
IPAddress test_z = WiFi.resolve("192.168.1.142") ;

if( test_x == test_y ){         // Test 1 
    Serial.println( "x == y" );
}
if( test_y == test_z ){         // Test 2 
    Serial.println( "y == z" );
}

Test 1 above passes if test_a and test_b are declared globally, outside of any functions; otherwise both tests fail.

My temporary workaround is just comparing individual octets

if( ( test_x[0] == test_y[0] ) &&
    ( test_x[1] == test_y[1] ) &&
    ( test_x[2] == test_y[2] ) &&
    ( test_x[3] == test_y[3] ) ){
        ....
}

Just wanted to bring this up since the documentation claims comparisons against IPAddress objects is possible.

@bkobkobko

This comment has been minimized.

Copy link
Contributor

commented Oct 26, 2015

You have some code shift from _a _b _c to _x _y _z but I think your idea is there.

You cannot run WiFi.resolve() to set a global variable outside of setup() or loop() since the network may or may not be running when you call it. You can call WiFi.resolve() in functions when the network is up and running of course.

Does that explain what you are seeing or is there some other problem?

@jakeypoo

This comment has been minimized.

Copy link
Contributor Author

commented Oct 26, 2015

oops, thanks edited the first comment to fix the variable names.

As I mentioned before. The comparison passes if you compare each byte individually but not if you compare IPAddress objects. So the actual values are being set properly, the comparison just doesn't work.

@m-mcgowan

This comment has been minimized.

Copy link
Contributor

commented Oct 26, 2015

Thanks for the test case. I believe it's the version field possibly not being set by all control paths. I'll add this to our internal test suite so that we can be sure this doesn't appear again.

@m-mcgowan m-mcgowan added this to the 0.4.9 milestone Jan 11, 2016

m-mcgowan added a commit that referenced this issue Jan 18, 2016

@m-mcgowan m-mcgowan closed this Jan 18, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.