Page 2 of 7 FirstFirst 1234 ... LastLast
Results 11 to 20 of 67

Thread: How to import data from wifi into arduino?

  1. #11
    Kart Driver
    Join Date
    Feb 2016
    Location
    ERR404
    Posts
    77
    Platform
    PS4
    Hi Memoric..

    I'm doing the same thing, and have got the ESP to connect directly to the UDP stream, and recieve packets of size 1367.. So far...


    I've coded the ESP8266 directly (as per Arduino) by installing the ESP8266 Arduino core off Github..

    Sorry if this is sucking eggs, but gotta make sure..

    Type this into Preferences/additional boards manager url's

    http://arduino.esp8266.com/stable/pa...com_index.json

    Then, goto Tools/Boards/Boards manager, and install the ESP8266 generic drivers.. This allows the Arduino IDE to recognise the ESP as a board in its own right..


    I've found a few wiring examples, but have found this to work..

    CH_PD, RST and GPIO2 each pulled to VCC (3v3, NOT 5v) via a 3k3 resistor.

    GPOI 0 plugged directly to GND, THEN power up, for 'Flash' mode.. Programs exactly the same as an UNO, Teensy, etc..
    Remove GPIO 0 from GND after burning.. Mine just floats.. (i.e. connected to nothing)..

    I'm reading the OP thru the serial Monitor at the moment, but plan to send the serial to a Teensy for processing..

    I've now got lost trying to decypher the stream, as most peeps are using 'struct' directly thr C, not 'Arduino C'...


    The code is a hash of 'ESP8266 Wifi scan' and the standard WiFi Libs 'WiFiUDPsendreceivestring'

    //===============================================================
    //= Libraries
    //===============================================================
    // ESP8266 Wifi
    #include <ESP8266WiFi.h>

    // Standard Wifi UDP Lib
    #include <WiFiUdp.h>


    // Data struct for Pcars
    //#include "data_struct.h"
    // Data struct for Pcars
    //#include "data_struct2.h"

    //===============================================================
    //= Setup Definitions
    //===============================================================
    unsigned int localPort = 5606; // Pcars UDP Port on all platforms

    //===============================================================
    //= Storage section
    //===============================================================
    int status = WL_IDLE_STATUS;
    char ssid[] = "S5 Hotspot"; // your network SSID (name)
    char pass[] = "xxxxxxxxxx"; // your network password (use for WPA, or use as key for WEP)

    //char packetBuffer[255]; //buffer to hold incoming packet
    char packetBuffer[1367]; //buffer to hold incoming packet

    //char ReplyBuffer[] = "acknowledged"; // a string to send back - NOT USED

    //===============================================================
    //= 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);

    }

    //===============================================================
    //= 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);
    int len = Udp.read(packetBuffer, 1367);
    if (len > 0) packetBuffer[len] = 0;
    Serial.println("Contents:");
    Serial.println(packetBuffer);


    // Dont send a reply to PS4.... !!!
    // send a reply, to the IP address and port that sent us the packet we received
    // Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    // Udp.write(ReplyBuffer);
    // Udp.endPacket();
    }
    }

    //===============================================================
    //= 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


    Obviously you need to replace my 'S5 Hotspot' and ****** password, with your own..

    Port 5606 is the Pcars port on all platforms..
    Last edited by cyclicscooby; 11-02-2016 at 15:45.
    The following 2 users likes this Post: GForce, memoric77


  2. #12
    Kart Driver
    Join Date
    Feb 2016
    Location
    ERR404
    Posts
    77
    Platform
    PS4
    I should point out that it's not actually working, but it connecting to my network and receiving packets from the PS4 IP address and of the correct packet size (1367). The stream stops if the game is paused, so it's definately the right stream, but i've now got stuck myself trying to read the packet info..

    I get this thru the serial monitor..

    Received packet of size 1367
    From 192.168.43.24, port 62761
    Contents:
    Šx

    Received packet of size 1367
    From 192.168.43.24, port 62761
    Contents:
    Š€


    etc, etc...

    It's not a complete solution to your problem, but it's half way there...

    I have put a post on Arduino.cc asking for help, but no replies yet..
    https://forum.arduino.cc/index.php?topic=378431.0

    Also the thread on here has given the data structure, but as I said above, it's a bit beyond me..
    http://forum.projectcarsgame.com/sho...-UDP-streaming


    Hope that helps..


    Luv
    Chrisie..
    Last edited by cyclicscooby; 11-02-2016 at 15:54.
    The following user likes this Post: memoric77


  3. #13
    Superkart Pilot memoric77's Avatar
    Join Date
    May 2015
    Location
    Bochum, Germany
    Posts
    147
    Platform
    PS4
    Thanks for sharing Chrisie!!!

    Because I am a totally beginner with Arduino, it's beyond
    to me too. Couldnt habe done this and I think, I couldn't fix the existing problems. I hope that someone else with your skill can share his experience so you can solve it together. I am only able to copy this and modify but not to improve. I am sorry dont be able to help, cant only take but not give input.

    Hope you will keep it going on!!

    Thanks in advance.
    Put the pedal to the metal
    PSN ID: memoric77 | http://www.simracingliga.de/
    PS4 | SAMSUNG 55" UE55F6500 | Playseat Challenge + DIY Bodyshaker, Buttonbox & Gearshift & Tablet Holder |
    FANATEC GT3 RS V2 (FW 756) + CSP V2 PEDAL + SHIFTER https://youtu.be/lupNXmrUchc
    The following user likes this Post: GForce


  4. #14
    Kart Driver
    Join Date
    Feb 2016
    Location
    ERR404
    Posts
    77
    Platform
    PS4
    Hi Memoric..

    I got it working..

    I couldn't get my head around 'Structs' or Strings (with a capitol S..!! ) so I did it how I know.. Probably a terrible use of memory and speed, but it works..

    I recoded the data_struct.h file from 'projectcars' forum, into 'Arduino'.. So an 's8' field became a 'char' field, f32 to float, etc.... Then added it directly to the top of my code (this is probably a bad use of RAM)..

    I then had to work thru each 'byte' of the incoming data packet, and move the right byte(s), and convert them, to the correct type of field. i.e. a float..


    I only got it working last night, so I know it still need tidying, but if it helps you...


    Also.... I've only de-coded the ParticipantInfoStrings bit so far. The whole data_struct is in there, but only that packet is done.. And, my 1Mb ESP8266 is 44% full... !!!! I reckon doing the Telemetry packet would reach 100%, so...

    I'm going to move all the structure and decoding over to a Teensy, and just serial the packets from the ESP untouched...

    But.. For now, here's the code... (For the ESP directly, not an Arduino)...
    The following user likes this Post: memoric77


  5. #15
    Kart Driver
    Join Date
    Feb 2016
    Location
    ERR404
    Posts
    77
    Platform
    PS4
    Code:
    /*
     =====================
     = Pcars_udp_rx_v2.1 =
     =====================
    
      Version Control
      ===============
      V1 - Copy of esp8266/WiFiscan & WiFiUDPsendrecievestring merged.. 
           scan for finding Hotspot, udp for UDP.
           Recieves packet of size 1367 (Pcars packet size)
      V1.1 Tidy code & reformat.
           Changed packet size from 255 to 1367.
           
     *V2 - Retrieve packets and move to struct for analysis.
      V2.1 Removed Arduino-dash code.. 
      V2.2 Decode ParticipantInfoString
           * NOTE - ESP 44% Full...      
           * 
      Program Desciption
      ==================
      Connects to Hotspot (my S5 at present), reads UDP stream on Port 5606.
      Port 5606 is the default port for Pcars on all platforms.
      
      I/Os 
      ==== 
      Just ESP8266 at mo.
      Rx/Tx - serial (Tx > Tx / Rx > Rx on UNO) - Teensy probably opposite..
      ***  Move GPIO 0 to Gnd "BEFORE" rebooting, for flash mode.
      CH_PD & RST & GPIO2 pulled to VCC with 3k3.
    
    */
    
    //============================================================================
    //= Libraries
    //============================================================================
    // ESP8266 Wifi
    #include <ESP8266WiFi.h>
    
    // Standard Wifi UDP Lib
    #include <WiFiUdp.h>
    
    // Data struct for Pcars
    //#include "data_struct_arduino.h"
    
    
    //============================================================================
    //= Setup Definitions
    //============================================================================
    //unsigned int localPort = 2390;      // local port to listen on
    unsigned int localPort = 5606;        // Pcars UDP Port on all platforms
    
    //============================================================================
    //= Storage section
    //============================================================================
    int status = WL_IDLE_STATUS;
    char ssid[] = "S5 Hotspot";           //  your network SSID (name)
    char pass[] = "*********";           // your network password (use for WPA, or use as key for WEP)
    
    char packetBuffer[1367];              //buffer to hold incoming packet
    
    //============================================================================
    //= Original Struct's, re-done as fields
    // struct sParticipantInfoStrings
    //static const  unsigned long sPacketSize = 1347;
    unsigned int ParticipantInfoStrings = 1347;  // Is a sParticipantInfoStrings packet
    unsigned int ParticipantInfoStringsBuild;  // 0
    byte  ParticipantInfoStringsPacketType;  // 2
    char  CarName[64]; // 3
    char  CarClassName[64];  // 67
    char  TrackLocation[64]; // 131
    char  TrackVariation[64];  // 195
    char  Name[16][64];  // 259
    float FastestLapTime[16];  // 1283
    // 1347
    
    
    //struct sTelemetryData
    //  static const unsigned long sPacketSize = 1367;
    unsigned int Telemetry = 1347;     // Is a sParticipantInfoStrings packet
    unsigned int TelemetryBuild;       // 0
    byte TelemetryPacketType;          // 2
      
    // Game states
    byte GameSessionState;             // 3
    
    // Participant info
    char ViewedParticipantIndex;       // 4
    char NumParticipants;              // 5
    
    // Unfiltered input
    byte UnfilteredThrottle;           // 6
    byte UnfilteredBrake;              // 7
    char UnfilteredSteering;           // 8
    byte UnfilteredClutch;             // 9
    byte RaceStateFlags;               // 10
    
    // Event information
    byte LapsInEvent;                  // 11
    
    // Timings
    float BestLapTime;                 // 12
    float LastLapTime;                 // 16
    float CurrentTime;                 // 20
    float SplitTimeAhead;              // 24
    float SplitTimeBehind;             // 28
    float SplitTime;                   // 32
    float EventTimeRemaining;          // 36
    float PersonalFastestLapTime;      // 40
    float WorldFastestLapTime;         // 44
    float CurrentSector1Time;          // 48
    float CurrentSector2Time;          // 52
    float CurrentSector3Time;          // 56
    float FastestSector1Time;          // 60
    float FastestSector2Time;          // 64
    float FastestSector3Time;          // 68
    float PersonalFastestSector1Time;  // 72
    float PersonalFastestSector2Time;  // 76
    float PersonalFastestSector3Time;  // 80
    float WorldFastestSector1Time;     // 84
    float WorldFastestSector2Time;     // 88
    float WorldFastestSector3Time;     // 92
    
    unsigned int JoyPad;               // 96
    
    // Flags
    byte HighestFlag;                  // 98
    
    // Pit info
    byte PitModeSchedule;              // 99
    
    // Car state
    int OilTempCelsius;                // 100
    unsigned int OilPressureKPa;       // 102
    int WaterTempCelsius;              // 104
    unsigned int WaterPressureKpa;     // 106
    unsigned int FuelPressureKpa;      // 108
    byte CarFlags;                     // 110
    byte FuelCapacity;                 // 111
    byte Brake;                        // 112
    byte Throttle;                     // 113
    byte Clutch;                       // 114
    char Steering;                     // 115
    float FuelLevel;                   // 116
    float Speed;                       // 120
    unsigned int Rpm;                  // 124
    unsigned int MaxRpm;               // 126
    byte GearNumGears;                 // 128
    byte BoostAmount;                  // 129
    char EnforcedPitStopLap;           // 130
    byte CrashState;                   // 131
    
    float OdometerKM;                  // 132
    float Orientation[3];              // 136
    float LocalVelocity[3];            // 148
    float WorldVelocity[3];            // 160
    float AngularVelocity[3];          // 172
    float LocalAcceleration[3];        // 184
    float WorldAcceleration[3];        // 196
    float ExtentsCentre[3];            // 208
    
    // Wheels / Tyres
    byte TyreFlags[4];                 // 220
    byte Terrain[4];                   // 224
    float TyreY[4];                    // 228
    float TyreRPS[4];                  // 244
    float TyreSlipSpeed[4];            // 260
    byte TyreTemp[4];                  // 276
    byte TyreGrip[4];                  // 280
    float TyreHeightAboveGround[4];    // 284
    float TyreLateralStiffness[4];     // 300
    byte TyreWear[4];                  // 316
    byte BrakeDamage[4];               // 320
    byte SuspensionDamage[4];          // 324
    int BrakeTempCelsius[4];           // 328
    unsigned int TyreTreadTemp[4];     // 336
    unsigned int TyreLayerTemp[4];     // 344
    unsigned int TyreCarcassTemp[4];   // 352
    unsigned int TyreRimTemp[4];       // 360
    unsigned int TyreInternalAirTemp[4]; // 368
    float WheelLocalPositionY[4];      // 376
    float RideHeight[4];               // 392
    float SuspensionTravel[4];         // 408
    float SuspensionVelocity[4];       // 424
    unsigned int AirPressure[4];       // 440
    
    // Extras
    float EngineSpeed;                 // 448
    float EngineTorque;                // 452
    
    // Car damage
    byte AeroDamage;                   // 456
    byte EngineDamage;                 // 457
    
    // Weather
    char AmbientTemperature;           // 458
    char TrackTemperature;             // 459
    byte RainDensity;                  // 460
    char WindSpeed;                    // 461
    char WindDirectionX;               // 462
    char WindDirectionY;               // 463
    
    //sParticipantInfo 
    char ParticipantInfo[56]; // 464    ** Has a separate Struct that this will need breaking down into
                                       // 56*16=896
    float TrackLength;                 // 1360
    byte Wings[2];                     // 1364
    byte DPad;                         // 1366       
                                       // 1368 struct is padded to
    /*
    struct sParticipantInfo
    {
      int   sWorldPosition[3];           // 0
      unsigned int   sCurrentLapDistance;         // 6
      byte     sRacePosition;               // 8
      byte     sLapsCompleted;              // 9
      byte     sCurrentLap;                 // 10
      byte     sSector;                     // 11
      float   sLastSectorTime;             // 14
                                         // 16
    */
    
    unsigned int loop16 = 0;
    unsigned int loop64 = 0;
    
    
    //============================================================================
    //= 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();
    
      Serial.println("Starting UDP");
      Udp.begin(localPort);
    }
    
    //============================================================================
    //= 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());
          if (packetSize == ParticipantInfoStrings) {
              Serial.println("***** Received Participant Info Strings ***** ");
              Udp.read(packetBuffer, 1347);
              // read packetbuffer(x) into correct fields.
              // build is an uint. word is same as uint
              ParticipantInfoStringsBuild = word(packetBuffer[0], packetBuffer[1]);
              ParticipantInfoStringsPacketType = packetBuffer[2];
              for (int carname = 0; carname <=63; carname++) {
                  CarName[carname] = packetBuffer[(carname+3)];
     //             int temp_name = carname + 3;
     //             Serial.print("Carname [");Serial.print(carname);
     //             Serial.print("] is packetbuffer no");Serial.println(temp_name);
              }
              for (int carclassname = 0; carclassname <= 63; carclassname++) {
                  CarClassName[carclassname] = packetBuffer[(67 + carclassname)];
              }
              for (int tracklocation = 0; tracklocation <= 63; tracklocation++) {
                  TrackLocation[tracklocation] = packetBuffer[(131 + tracklocation)];
              }
              for (int trackvariation = 0; trackvariation <= 63; trackvariation++) {
                  TrackVariation[trackvariation] = packetBuffer[(195 + trackvariation)];
              }
              int packetno = 259;
              for (int name16 = 0; name16 <= 15; name16++) {  
                  for (int name64 = 0; name64 <= 63; name64++) {
                      Name[name16][name64] = packetBuffer[packetno];
                      packetno++;
                  }
              }    
              int packetno_2 = 1283;
              for (int fastestlaptime = 0; fastestlaptime <= 15; fastestlaptime++) {
                  unsigned long highWord = word(packetBuffer[packetno_2], packetBuffer[(packetno_2+1)]);
                  unsigned long lowWord = word(packetBuffer[(packetno_2+2)], packetBuffer[(packetno_2+3)]);
                  unsigned long newlong = highWord << 16 | lowWord;
                  FastestLapTime[fastestlaptime] = float(newlong);
                  packetno_2 += 4;
              }
              Serial.print("Raw Contents of ParticipantInfoStrings packetBuffer:");
              Serial.println(packetBuffer);
              Serial.print("Build:"); Serial.println(ParticipantInfoStringsBuild);
              Serial.print("Packet Type:"); Serial.println(ParticipantInfoStringsPacketType);
              Serial.print("Car Name:"); Serial.println(CarName);
              Serial.print("Car Class Name:"); Serial.println(CarClassName);
              Serial.print("Track Location:"); Serial.println(TrackLocation);
              Serial.print("Track Variation:"); Serial.println(TrackVariation);
              for (int nameloop = 0; nameloop <= 15; nameloop++) {
                Serial.print("Name "); Serial.print(nameloop);
                Serial.print(" is:"); Serial.println(Name[nameloop]);
              }
              for (int fastestlap = 0; fastestlap <= 15; fastestlap++) {
                Serial.print("Participant no "); Serial.print(fastestlap);
                Serial.print(" Fastest Lap :"); Serial.println(FastestLapTime[fastestlap]);
              }
              
          
          }
          else if (packetSize == Telemetry) {
              Udp.read(packetBuffer, 1367);
    
          }
    
    /*
          // read the packet into packetBufffer
          int len = Udp.read(packetBuffer, 1367);
          if (len > 0) packetBuffer[len] = 0;
          Serial.print(" - Contents:");
          Serial.println(packetBuffer);
    */
    
      }
    }
    
    //============================================================================
    //=  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

    Hope that helps...


    Luv
    Chrisie..
    The following 2 users likes this Post: GForce, memoric77


  6. #16
    Superkart Pilot memoric77's Avatar
    Join Date
    May 2015
    Location
    Bochum, Germany
    Posts
    147
    Platform
    PS4
    Hello Chrisie,

    what can I say? This is a stunning work work from you and I thank you that you are sharing your hard work here!

    This is the code of the currently only on the esp running but you want to port the output of the received data to the serial port of the leonardo? because only this can even process the information. I would want to use only certain information. Then it would be best just to filter on the esp only this information and transmitted serially or? Minimizes the workload of the ESP. I would not have done, many thanks again, my respect!

    Would it be possible that you have a drawing via fritzing of the connection of the esp to the leonardo and the arduino IDE, so you can program it? I managed this only once with a uno, but it is indeed the leonardo needed. This would illustrate it again. Then I could test it directly and test further steps from you. You will many readers have done a big favor.

    greets
    Markus
    Put the pedal to the metal
    PSN ID: memoric77 | http://www.simracingliga.de/
    PS4 | SAMSUNG 55" UE55F6500 | Playseat Challenge + DIY Bodyshaker, Buttonbox & Gearshift & Tablet Holder |
    FANATEC GT3 RS V2 (FW 756) + CSP V2 PEDAL + SHIFTER https://youtu.be/lupNXmrUchc
    The following user likes this Post: GForce


  7. #17
    Kart Driver
    Join Date
    Feb 2016
    Location
    ERR404
    Posts
    77
    Platform
    PS4
    A bit of an explanation, cuz if you're as confused as I was, it might help...

    Next to the fields in the definitions, are //3, etc.. This is the start byte of that field, within the 1347 packet bytes

    Back to basics, just in case..

    char = Signed 8bits (1byte)
    byte = Unsigned 8bits (1byte)
    int = Signed 16bits (2bytes)
    unsigned int/word = Unsigned 16bit (2bytes)
    float = Signed 32bit (4bytes)
    unsigned long = Unsigned 32bit (4bytes)


    So.. If you need byte or char data(1byte), just move a single byte from the packet directly to the field.
    i.e.
    Code:
    char_x = packetBuffer[x];

    If you need to extract an int or word, which is TWO bytes, you need to use TWO sequential bytes from the packetBuffer..
    So int_x = packetBuffer[x] & packetBuffer[y]...

    word() converts two separate bytes into a word (this is what was used in the code I nicked. Its exactly the same as an unsigned int )

    The code looks like...
    Code:
    int_x = word(packetBuffer[x], packetBuffer[y]);

    Finally, if you need a float, or long, which is 4bytes long... i.e packetBuffer[1] & packetBuffer[2] & packetBuffer[3] & packetBuffer[4]

    You do the above 'int' conversion twice, (packetBuffer[1] & [2] then, packetBuffer[3] & [4] then add those two TWO byte ints together,
    to be a float...

    So, as before, but with names that'll help..
    First create two words

    Code:
    unsigned long highWord = word(packetBuffer[1], packetBuffer[2]);
               unsigned long lowWord = word(packetBuffer[3], packetBuffer[4]);
    The reason for calling then high and low, is because you're now going to put the together into a 4byte fields like this 'HIGHLOW'

    This uses bit shifting to move HIGH (2bytes 16bits) to the top (leftside) of a 32bit field, then move LOW into the lower 16bits, creating ONE 32bit (4byte) field...

    Code:
    float_x = float((highWord << 16 | lowWord));

    And thats it... All you need to extract all the data from the UDP...

    Happy coding (or copying.. )


    Luv
    Chrisie.. xx
    The following 2 users likes this Post: GForce, memoric77


  8. #18
    Kart Driver
    Join Date
    Feb 2016
    Location
    ERR404
    Posts
    77
    Platform
    PS4
    Quote Originally Posted by memoric77 View Post
    Hello Chrisie,

    what can I say? This is a stunning work work from you and I thank you that you are sharing your hard work here!

    This is the code of the currently only on the esp running but you want to port the output of the received data to the serial port of the leonardo? because only this can even process the information. I would want to use only certain information. Then it would be best just to filter on the esp only this information and transmitted serially or? Minimizes the workload of the ESP. I would not have done, many thanks again, my respect!

    Would it be possible that you have a drawing via fritzing of the connection of the esp to the leonardo and the arduino IDE, so you can program it? I managed this only once with a uno, but it is indeed the leonardo needed. This would illustrate it again. Then I could test it directly and test further steps from you. You will many readers have done a big favor.

    greets
    Markus

    Thankyou Memoric..

    Yes, Its just the ESP, plugged into an FTDI cable, but I did have it 'bodged' into the Arduino successfully for a week (as in, bypassing the UNO and just hijacking its USB to Serial Port to code the ESP - UNO loaded with empty sketch, and code complied as ESP, NOT UNO, so UNO ignores upload)
    NOTE..... You're not supposed to do this, because the ESP is 3v3 ONLY, on TxRx and the UNO 3v output isnt supposed to be powerful enuf to power the ESP.... BUT, it worked for me, for a week, until my FTDI cable and some 3v regulators arrived...

    Mines on Breadboard, with flyleads..

    Vcc to a 3v3 Regulator,
    Gnd to Gnd (and the FDTI Gnd to same GND) - OR UNO Gnd and 3v3, if you use it that way
    ESP Tx to FDTI Rx
    ESP Rx to FDTI Tx
    NOTE - 'IF' you connect it via an UNO, Tx goes to Tx, Rx to Rx. The UNO appears to be marked with what to 'plug in', NOT what it is..!!

    Then, CH_PD, RST, and GPIO2 each get pinned to Vcc via a 3k3 pullup resistor.

    GPIO 0 is left floating (plugged into nothing) if turning on to run..

    If you want to code the ESP, you just plug GPIO 0 to GND, BEFORE you power up the ESP, and leave it there until you're finished..


    I've found you have to be quick pressing upload (within 3-5secs) after booting up, otherwise it's be off looking for Wifi.. and you'll get

    'ESPCOMM not responding'

    If it does, just power off, power on, try again..


    Regarding Serial out to another MCU. Thats exactly what i'm looking into now..

    As soon as I find a good (easy) way, i'll get back to you...


    Luv
    Chrisie.. xx
    The following 2 users likes this Post: GForce, memoric77


  9. #19
    Kart Driver
    Join Date
    Feb 2016
    Location
    ERR404
    Posts
    77
    Platform
    PS4
    Soz, forgot.. Regarding stripping off what you need in the ESP and sending just that...

    You dont have to define every field in the data_struct. You could just code what you need, which would save valuable space..

    BUT, my thinking, is.. When you send the stripped out data from the ESP to another MCU, you'll have to code in a way of telling the data apart, at the other end.. OR re-concatenate it to a single stream, and send that, but you'll have to de-cypher it AGAIN in the second MCU....

    I'm not sure of the Leonardo's Specs, but i've got a couple of Teensy 3.1's which are way more powerful than either an UNO or the ESP, so...
    I plan to send the whole unpacked packetBuffer, serially, to a Teensy. That means the ESP doesn't need any of the fields defined (other than packetBuffer) and can just Rx the UDP and serial it straight back out..

    I don't yet know if it'll all be quick enuf to keep up, I presume it will at 115200 baud, but if you don't try....


    Luv
    Chrisie.. xx

  10. #20
    Kart Driver
    Join Date
    Feb 2016
    Location
    ERR404
    Posts
    77
    Platform
    PS4
    Just been reading this... Might help us..

    https://forum.arduino.cc/index.php?topic=333118.15


    Guy getting latency issues sending serial packet data from an ESP, to a Mega...


    It may be worth stripping the data you want IN the ESP, and moving it to another, but smaller packetBuffer, maybe adding a 'packet_type' byte at the beginning. Then sending that smaller packet to the other MCU..

    Apparently, because the WiFi and UDP libs are quite large, and the ESP needs to keep checking for new network data (which it does each time the code goes round), IF you've got a loop that takes over 50ms, you need to add a small 'delay', as the ESP uses 'delay' to go off and do it's WiFi bit. So 'Delay(2)' wont upset the code too much, but does keep the ESP Wifi happy... !?!


    Like you, I dont need ALL the data, just Dash board, button box stuff, and Motion chair data, but for now, I want to see ALL the data IF I can... If only for testing, so i'm going to stick with the entire packet, and no de-coding on the ESP...
    But that may change...

    Anyway... Enuf on here, time to code...


    Nite nite..

    Luv
    Chrisie.. xx
    Last edited by cyclicscooby; 13-02-2016 at 22:35.
    The following user likes this Post: GForce


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: 687
    Last Post: Today, 06:08
  2. Arduino Dashboard
    By saibot852 in forum General Discussion
    Replies: 217
    Last Post: 23-02-2017, 21:47
  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
  •