motorTestingOtaMultiTaskWire/src/main.cpp
// Called when receiving any WebSocket message
Called when receiving any WebSocket message
Called when receiving any WebSocket message
void onWebSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
  switch(type) {
    case WStype_DISCONNECTED:
      Serial.printf("[%u] Disconnected!\n", num);
      break;
    case WStype_CONNECTED:
      {
        IPAddress ip = webSocket.remoteIP(num);
        Serial.printf("[%u] Connection from ", num);
        Serial.println(ip.toString());
      }
      break;
    case WStype_TEXT:
      Serial.printf("[%u] Command: %s\n", num, payload);
      flightCommand = "" + String(reinterpret_cast<char*>(payload));
      throtle = flightCommand.substring(2,6).toInt();
      wing=flightCommand.substring(8,11).toInt();
      elevator=flightCommand.substring(13,16).toInt();
      rudder=flightCommand.substring(18,21).toInt();
      refreshBtn = flightCommand.substring(23,24).toInt();
      wingsTogether = flightCommand.substring(26,27).toInt();
      volanAngle[0] = 180 - wing;
      if (wingsTogether)
        volanAngle[1] = wing;
      else
        volanAngle[1] = 180 - wing;
      volanAngle[2] = 180 - elevator;
      volanAngle[3] = elevator;
      volanAngle[4] = rudder;
      break;
    case WStype_BIN:
    case WStype_ERROR:
    case WStype_FRAGMENT_TEXT_START:
    case WStype_FRAGMENT_BIN_START:
    case WStype_FRAGMENT:
    case WStype_FRAGMENT_FIN:
    default:
      break;
  }
}
void onWebSocketEvent ( uint8_t num , WStype_t type , uint8_t * payload , size_t length ) { switch ( type ) { case WStype_DISCONNECTED : Serial . printf ( " \n " , num ) ; break ; case WStype_CONNECTED : { IPAddress ip = webSocket . remoteIP ( num ) ; Serial . printf ( " " , num ) ; Serial . println ( ip . toString ( ) ) ; } break ; case WStype_TEXT : Serial . printf ( " \n " , num , payload ) ; flightCommand = " " + String ( reinterpret_cast < char * > ( payload ) ) ; throtle = flightCommand . substring ( 2 , 6 ) . toInt ( ) ; wing = flightCommand . substring ( 8 , 11 ) . toInt ( ) ; elevator = flightCommand . substring ( 13 , 16 ) . toInt ( ) ; rudder = flightCommand . substring ( 18 , 21 ) . toInt ( ) ; refreshBtn = flightCommand . substring ( 23 , 24 ) . toInt ( ) ; wingsTogether = flightCommand . substring ( 26 , 27 ) . toInt ( ) ; volanAngle [ 0 ] = 180 - wing ; if ( wingsTogether ) volanAngle [ 1 ] = wing ; else volanAngle [ 1 ] = 180 - wing ; volanAngle [ 2 ] = 180 - elevator ; volanAngle [ 3 ] = elevator ; volanAngle [ 4 ] = rudder ; break ; case WStype_BIN : case WStype_ERROR : case WStype_FRAGMENT_TEXT_START : case WStype_FRAGMENT_BIN_START : case WStype_FRAGMENT : case WStype_FRAGMENT_FIN : default : break ; } }
Called when receiving any WebSocket message
Called when receiving any WebSocket message
// Figure out the type of WebSocket event // Client has disconnected // New client has connected // Recived message from client //reinterpret_cast<char*>(payload); //flightCommand = "m:0000w:000e:000t:000r:0z:1" //webSocket.broadcastTXT(flightCommand.c_str()); //webSocket.sendTXT(0, flightCommand); // For everything else: do nothing