HC 06 data receiving

Hello!
I've wrote a script in python which sends data through PC's bluetooth to HC-06 on arduino.

state is integer from 0 to 1000 (it is controlled through potentiometer)

...
gaugeSocket.send(str(state))...

I have a problem, because I can't get right character to integer conversion on arduino (from HC-06 serial).

SoftwareSerial mySerial(10, 11); // RX, TX
char buf[2];
int i=0;
int data;
int ledPin = 9; 

void setup() {
    pinMode(ledPin, OUTPUT); 
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  mySerial.begin(9600);
}

void loop() { // run over and over
  if (mySerial.available()) {
    for(;i<2;){
      buf[i] = mySerial.read(); 
      i++;
    }
    i = 0;
    Serial.print(buf);
    data = atoi(buf);
  }

    analogWrite(ledPin, data/10); //To see how code behaves on LED
}

This is the output (from Serial.print(buf)):

0ÿ(0ÿ(0ÿ(0ÿ(0ÿ(0ÿ(0ÿ(60(1ÿ(00(16(0ÿ(23(0ÿ(30(0ÿ(3ÿ(60(43(0ÿ(49(0ÿ(53(0ÿ(5ÿ(90(69(0ÿ(88(0ÿ(10(00(10(00(10(

if I turn the potentiometer from 0 to 1000.

What am I missing?

Thank you

The usual - check that there's a character to read, and then read both of them.

Hello,

Is it me or is the OP using two different serial read numbers? 9600 and 57600?

Also, atoi works only C style strings.

PilotinControl:
Hello,

Is it me or is the OP using two different serial read numbers? 9600 and 57600?

So?
Different interfaces.

AWOL thanks for your answer, but can you be more specific please?

Interface 1 SoftwareSerial mySerial(10, 11);
Interface 2   Serial.begin(57600);

No, I meant with this:

"The usual - check that there's a character to read, and then read both of them."

 if (mySerial.available()) {
    for(;i<2;){
      buf[i] = mySerial.read();
      i++;
    }

Check to see there's at least one character to read, then read both of them.

I can't really see how more specific I could be.