Split from: GPRS sim800

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

HI Guys,

I have managed to get "some" of the websockets to work on the SIM800 unit. 

What I have achieved so far:

  1. My arduino can log onto my websockets server via the sim800 GPRS
  2. It can connect as a user
  3. It displays any broadcast message from the server to the sim800. 

BUT it does NOT send messages yet..fr the life of me i cant get it right. 

I am encoding the messages correctlyas per spec but still no luck :-( Here is my code so far:

 

void GPRSSocketsUpgrade()
{

  /*Sample Websocket header
     GET /chat HTTP/1.1
    Host: server.example.com
    Upgrade: websocket
    Connection: Upgrade
    Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==
    Sec-WebSocket-Protocol: chat, superchat
    Sec-WebSocket-Version: 13
    Origin: http://example.com
  */


  Serial.println("Connecting to sim800");
  // if there's a successful connection:
  sim800.println("AT+CREG?");
  delay(1000);
  sim800.println("AT+CGATT?");
  delay(1000);

  sim800.println("AT+CIPCLOSE");
  delay(1000);

  sim800.println("AT+CSTT=\"internet\"");
  delay(1000);

  sim800.println("AT+CIICR");
  delay(100);

  sim800.println("AT+CIFSR");
  delay(100);

  sim800.println("AT+CIPSTART=\"TCP\",\"205.x.x.x\",\"80\"");
  delay(3000);

  sim800.flush();

  sim800.println("AT+CIPSEND");
  delay(100);

  Serial.println(F("handshaking..."));
  // send the HTTP GET request:
  sim800.println(F("GET /sox/xxxx.ashx?UN=pieti HTTP/1.1"));
  sim800.println(F("Host: xxxxx.co.za"));
  sim800.println(F("Upgrade: websocket"));
  sim800.println(F("Connection: Upgrade"));
  sim800.println(F("Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw=="));
  sim800.println(F("Sec-WebSocket-Protocol: chat, superchat"));
  sim800.println(F("Sec-WebSocket-Version: 13"));
  sim800.println();
  sim800.println((char)26); //CTRL-Z
}

that works fine...it connects/handshakes and upgrades the socket connection via tcp just fine.

 

i can also read all incoming broadcasts with this routine without fail:

//in the loop
  if (sim800.available())
  {
    Serial.write(sim800.read());
  }

BUT...the minute i try this...the whole thing falls over...and weirdly enough I cont get a DISCONNECT from the server...

void GPRSsendEncodedData(char *str, uint8_t opcode) {
  uint8_t mask[4];
  int size = strlen(str);
  Serial.println(str);
  
  // Opcode; final fragment
  sim800.print(opcode | WS_FIN);

  // NOTE: no support for > 16-bit sized messages
  if (size > 125) {
    sim800.print(WS_SIZE16 | WS_MASK);
    sim800.print((uint8_t) (size >> 8));
    sim800.print((uint8_t) (size & 0xFF));
  } else {
    sim800.print((uint8_t) size | WS_MASK);
  }

  mask[0] = random(0, 256);
  mask[1] = random(0, 256);
  mask[2] = random(0, 256);
  mask[3] = random(0, 256);

  sim800.print(mask[0]);
  sim800.print(mask[1]);
  sim800.print(mask[2]);
  sim800.print(mask[3]);

  for (int i = 0; i < size; ++i) {
    sim800.print(str[i] ^ mask[i % 4]);
  }

//  sim800.println(); 
}

has anyone managed to get the sim800 to work?

 

Regards

Paul

Last Edited: Mon. Nov 20, 2017 - 11:31 AM