App says device is online but wont control project

The “2” in the code above means GPIO Pin 2. This is not the same as the pin that’s labelled “D2” on the board. The Blue LED on the board is connected to GPIO2 and is active (lit) when the pin is pulled LOW.

See this diagram for the mapping of GPIO numbers to pin labels:

You should also read this topic about “safe” pins to use:

Pete.