Page 8 of 8 FirstFirst ... 678
Results 71 to 72 of 72

Thread: How to import data from wifi into arduino?

  1. #71
    Superkart Pilot Killg0re NL's Avatar
    Join Date
    Sep 2017
    Location
    Netherlands
    Posts
    171
    Platform
    PS4 Pro
    Quote Originally Posted by fmiglior View Post
    Yes, a reproduce. a made some changes on the code to use de Pcars 2 UDP parametes and to use a ESP32 and a TFT display.

    but i'm having some problems with the timings pack. i can't find on the udp pack the current lap time and other times and i don't know how to convert the info to the format 00:00.000

    someone can help?

    Thanks!
    How far are you? and willing to share the code?

    I am quite far, (but not workings on the timing). i am working on making it UDP version independent, and to get the code working more efficiently.
    Carflags 6 and 7 don't seem to work (ESP and TCS) and can't calculate the fuel lavel correctly.

    now working with racestate and gamestate, but those bits also arn't what i am expecting of it.

    am thinking of publishing the code, just to share and hopefully, to get some help/feedback.

  2. #72
    Rookie
    Join Date
    Jun 2015
    Posts
    2
    Platform
    PC
    Quote Originally Posted by Killg0re NL View Post
    How far are you? and willing to share the code?

    I am quite far, (but not workings on the timing). i am working on making it UDP version independent, and to get the code working more efficiently.
    Carflags 6 and 7 don't seem to work (ESP and TCS) and can't calculate the fuel lavel correctly.

    now working with racestate and gamestate, but those bits also arn't what i am expecting of it.

    am thinking of publishing the code, just to share and hopefully, to get some help/feedback.

    after the post i stop the project... last week i was trying to use de UDP the ESP 32 and a CAN transeiver to use a car dashboard and it works =]


    i can't find the esp, tcs and pit limit on the carflags.. ABS, ENGINE ACTIVE, ENGINE WARNING, LIGHTS is OK.

    To calculate the fuel, you have to use the sFuelLevel [4 - use the same convertfloat as the speed] i'ts give you the % of fuel. mutiply by sFuelCapacity to have the Liters on the tank.


    But i didn't sucess with laptime =[


    if you want to email me, it is easier to help


    Code:
    /===============================================================
    //= Libraries
    //===============================================================
    // ESP32 Wifi
    #include <WiFi.h>
    
    // Standard Wifi UDP Lib
    #include <WiFiUdp.h>
    
    
    
    //===============================================================
    //= Setup Definitions
    //===============================================================
    unsigned int localPort = 5606; // porta udp do pcars
    //===============================================================
    //= Storage section
    //===============================================================
    int status = WL_IDLE_STATUS;
    
    char ssid[] = " "; // your network SSID (name)
    char pass[] = " "; // your network password (use for WPA, or use as key for WEP)
    //char packetBuffer[255]; //buffer to hold incoming packet
    char packetBuffer[1600]; //buffer to hold incoming packet
    //float packetBuffer; //buffer to hold incoming packet
    //char ReplyBuffer[] = "ok"; // a string to send back - NOT USED
    int vGear;
    word nome;
    unsigned char sCarFlags;
    //===============================================================
    //= Setup objects
    //===============================================================
    WiFiUDP Udp; // Create Udp object
    
    //===============================================================
    //= Setup
    //===============================================================
    void setup() {
    //Initialize serial and wait for port to open:
    delay(2000);
    Serial.begin(115200);
    while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
    }
    
    // attempt to connect to Wifi network:
    while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    
    // wait 10 seconds for connection:
    delay(10000);
    }
      Serial.println("Connected to wifi");
    //  printWifiStatus(); // Just prints connection details
      
      Serial.println("Starting UDP");
      Udp.begin(localPort);
    
    }
    
    union {
      byte uBytes[4];
      float uFloat;
      long uLong;
    } uData;
    
    union {
      byte sBytes[4];
      float sFloat;
      long sLong;
    } sData;
    
    
    //===============================================================
    //= Main Loop
    //===============================================================
    void loop() {
    
    // if there's data available, read a packet
    int packetSize = Udp.parsePacket();
    if (packetSize) {
    //Serial.print("Received packet of size ");
    //Serial.println(packetSize);
    //Serial.print("From ");
    IPAddress remoteIp = Udp.remoteIP();
    //Serial.print(remoteIp);
    //Serial.print(", port ");
    //  Serial.println(Udp.remotePort());
    
    // read the packet into packetBufffer
    // int len = Udp.read(packetBuffer, 255);
     Udp.read(packetBuffer, 1600);
     //int len = Udp.read(packetBuffer);
    //if (len > 0) packetBuffer[len] = 0;
    //Serial.println("Contents:");
    //Serial.println(packetBuffer);
    //byte swing2 = packetBuffer[12];
    //byte swing3 = packetBuffer[12];
    //Serial.print("teste:");Serial.print(swing2);Serial.print(" - ");Serial.println(swing3);
    
    if (packetSize == 559){ 
         byte marcha = packetBuffer[45];
         int marchaatual = marcha & 0xf;
         //Serial.print("marcha: ");Serial.println(marchaatual); //GEAR INDICATOR
    byte acel = map(packetBuffer[30],0,255,0,100);
         //Serial.print("acel: ");Serial.println(acel); //Throttler %
    unsigned char carflags = packetBuffer[17];
        // Serial.print("pit: ");Serial.println(bitRead(carflags,0)); // 1 if the car is in the pitlane
    byte bbias = packetBuffer[554];
    int bia = (100-bbias/2.55) ;
      //   Serial.print("Bbias: ");Serial.println(bia ); //Brake Bias 
         byte swing1 = map(packetBuffer[371],0,255,0,100);
    //Serial.print("swing1 :");Serial.println(swing1);
    byte swing2 = packetBuffer[28];
    //Serial.print("swing2 :");Serial.println(swing2);
    sCarFlags =packetBuffer[17];
    Serial.println (sCarFlags);
    //float CurrentTime = (packetBuffer[10]) << 24 | (inBuffer[9] & 0xff) << 16 | (inBuffer[8] & 0xff) << 8 | (inBuffer[7] & 0xff);
    //Serial.print("nome :");Serial.println();
    //convertFloat();
     
    }
        }
    
    
    }
    
     void convertFloat() {
    
      uData.uBytes[0] = packetBuffer[36];
      uData.uBytes[1] = packetBuffer[37];
      uData.uBytes[2] = packetBuffer[38];
      uData.uBytes[3] = packetBuffer[39];
    int velocidade = (uData.uFloat) *3.6;
    
    Serial.print("speed :");Serial.println(velocidade); //Speed KMh
    
     }
    //===============================================================
    //= Serial print WiFi details 
    //===============================================================
    void printWifiStatus() {
    // print the SSID of the network you're attached to:
    Serial.print("SSID: ");
    Serial.println(WiFi.SSID());
    // print your WiFi shield's IP address:
    IPAddress ip = WiFi.localIP();
    Serial.print("IP Address: ");
    Serial.println(ip);
    // print the received signal strength:
    long rssi = WiFi.RSSI();
    Serial.print("signal strength (RSSI):");
    Serial.print(rssi);
    Serial.println(" dBm");
    }
    
    // END OF PROGRAM

Similar Threads

  1. [PC/XB1/PS4] vrHive - Dashes/Telemetry/Live Data/Arduino/Client-Server/+more
    By MikeyTT in forum Third-Party Apps & API Discussion
    Replies: 761
    Last Post: 11-10-2019, 11:42
  2. Arduino Dashboard
    By saibot852 in forum General Discussion
    Replies: 219
    Last Post: 04-09-2017, 04:41
  3. Import 3D model in game?
    By choptider in forum PC - Technical Help & Support
    Replies: 4
    Last Post: 25-11-2015, 02:54
  4. Logic3 TopDrive GT racing wheel not detected (Wifi dongle)
    By markieg in forum PC - Technical Help & Support
    Replies: 0
    Last Post: 09-10-2015, 12:12
  5. calling all arduino nuts
    By brooksy in forum General Discussion
    Replies: 2
    Last Post: 25-05-2015, 09:35

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •