Lost i2c signal, Arduino stuck

Hello,

I bought a Infrared temperature sensor that is communicating with arduino uno via I2C.
But sometimes the arduino is losing the signal. This happens when the connector doesn’t make a good contact.
i’am not able to improve the connector or solder it.

When the signal is lost for a very short time, the arduino is stuck. It doesn’t do anything until i reset it.
I want that if the signal is lost, the arduino will try again.

Is there a solution for this?

#include <i2cmaster.h>

void setup(){
	i2c_init();
	PORTC = (1 << PORTC4) | (1 << PORTC5);

       Serial.begin(9600);

        delay(1000);
}

void loop()
{
    int dev = 0x5A<<1;
    int data_low = 0;
    int data_high = 0;
    int pec = 0;
    
    i2c_start_wait(dev+I2C_WRITE);
    i2c_write(0x07);
    
    i2c_rep_start(dev+I2C_READ);
    data_low = i2c_readAck(); 
    data_high = i2c_readAck();
    pec = i2c_readNak();
    i2c_stop();
    
    double tempFactor = 0.02; 
    double tempData = 0x0000; 
    int frac; 

    tempData = (double)(((data_high & 0x007F) << 8) + data_low);
    tempData = (tempData * tempFactor)-0.01;

    float celcius = tempData - 273.15;
    Serial.print("Celcius: ");
    Serial.println(celcius);

   delay(1000);

Is there a solution for this?

Since your posted code is incomplete, no.

i'am not able to improve the connector or solder it.

Why not?

ok, i've posted the whole code in my first post.

I'm using it on a off-road vehicle and the sensor has to be removed very often. so i'm looking for a software solutions.

ok, i've posted the whole code in my first post.

Well, then I posted the whole answer in my first reply..

I would fix the connector. But if you can't, take a look at how the I2C scanner program for Arduino works. It tries to communicate with a device at a given address and if no answer is received, moves on. You could adopt that approach.