fit-php icon indicating copy to clipboard operation
fit-php copied to clipboard

Incorrect header size

Open cgkronos opened this issue 4 years ago • 0 comments

Hello there, I'have an array "stepsData":

{"0":{"power":112.5,"hr":99.75,"cadence":90},"660":{"power":175,"hr":142.5,"cadence":90},"990":{"power":175,"hr":142.5,"cadence":90},"2550":{"power":225,"hr":161.5,"cadence":90},"3150":{"power":175,"hr":142.5,"cadence":90},"3750":{"power":350,"hr":185.25,"cadence":90},"3780":{"power":175,"hr":161.5,"cadence":90},"3810":{"power":350,"hr":185.25,"cadence":90},"3840":{"power":175,"hr":161.5,"cadence":90},"3870":{"power":350,"hr":185.25,"cadence":90},"3900":{"power":175,"hr":161.5,"cadence":90},"3930":{"power":350,"hr":185.25,"cadence":90},"3960":{"power":175,"hr":161.5,"cadence":90},"3990":{"power":350,"hr":185.25,"cadence":90},"4020":{"power":175,"hr":161.5,"cadence":90},"4050":{"power":350,"hr":185.25,"cadence":90},"4080":{"power":175,"hr":161.5,"cadence":90},"4110":{"power":175,"hr":142.5,"cadence":90},"4950":{"power":800,"hr":142.5,"cadence":125},"4960":{"power":112.5,"hr":142.5,"cadence":90},"5010":{"power":800,"hr":142.5,"cadence":125},"5020":{"power":112.5,"hr":142.5,"cadence":90},"5070":{"power":800,"hr":142.5,"cadence":125},"5080":{"power":112.5,"hr":142.5,"cadence":90},"5130":{"power":800,"hr":142.5,"cadence":125},"5140":{"power":112.5,"hr":142.5,"cadence":90},"5190":{"power":800,"hr":142.5,"cadence":125},"5200":{"power":112.5,"hr":142.5,"cadence":90},"5250":{"power":175,"hr":142.5,"cadence":90},"6810":
{"power":112.5,"hr":99.75,"cadence":90}}

And I use this fork https://github.com/johnnye/fit-php like this

public function generateWahooWorkoutFit($trainingpplansession,$stepsData,$fitpath){
        $time = time() - mktime(0,0,0,12,31,1989);
        $data = new \Fit\Data;
        $data->setFile(\Fit\FileType::workout);
        $data
            ->add('file_id', array(
                'type'                  => \Fit\FileType::workout,
                'manufacturer'          => \Fit\Manufacturer::development,
                'product'               => 0,
                'serial_number'         => 0,
                'time_created'          => $time,
            ))->add('event', array(
                'timestamp'             => $time,
                'event_type'            => \Fit\EventType::start,
                
            ))->add('session', array(
                'sport'                 => \Fit\Sport::cycling,
                'sub_sport'             => \Fit\SubSport::generic,
                'total_elapsed_time'    => $trainingpplansession->getDuration(),
                'total_timer_time'      => $trainingpplansession->getDuration(),
                'total_distance'        => 0,
                'total_ascent'          => 0,
        ));

        foreach ($stepsData as $timestamp=>$stepdata){
            $data->add('record', array(
                'timestamp'             => $timestamp+$time, 
                //'position_lat'          => 0, 
                //'position_long'         => 0, 
                //'altitude'              => 0, 
                'heart_rate'            => $stepdata["hr"],
                'cadence'               => $stepdata["cadence"], 
                //'distance'              => 0, 
                'power'                 => $stepdata["power"], 
                //'temperature'           => 0, 
             ));
        }
        $data->add('event', array(
            'timestamp'             => $trainingpplansession->getDuration()+$time,
            'event_type'            => \Fit\EventType::stop,
        ));


        $debug = false;
        
        //Write the data
        $fitwriter = new \Fit\Writer($debug);
        $fitwriter->writeData($data,$fitpath);
        
        
        //Read the data that was just created
        /*$fit = new \Fit\Reader(true);
        $fit->parseFile($filepath, $debug);
        
        //Delete the written data
        unlink($filepath);
        var_dump($fit);*/
    }

The generated fit (https://www.dropbox.com/s/adc1icycm893zd2/WAHOO-2021-07-13.fit?dl=0) is sent to wahoo we contacted the support who reply us:

It looks like your base64 encoding, data url, and request format are all correct. However, there is a problem with your FIT file that is preventing our cloud from parsing it. We are failing because of an “Incorrect header size.” I recommend using a different tool to generate your FIT file. Once you have a valid FIT file your request should work.

So I'm curious if I do something wrong with the library

Thanks in advance

cgkronos avatar Jul 16 '21 13:07 cgkronos