Try to send \r\n
instead of just \r
as end-of-line terminator. I think it's your problem.
Otherwise, use wireshark to monitor the TCP communication between a "manual" telnet session and your device: you will see what it sends exactly and you will see what you have to send...