P0171 fault code

Hi, new member here, I have a 2002 MX5 1.8 MK2.5 and I am having an issue with a P0171 code.

I have checked for vacuum leaks, checked the o2 sensors and I’m out of ideas. If I clear the code the car will run fine for 2/3 days and then it’ll come back, when it’s back the revs will be up and down at idle.

I will get readings on the fuel trim, MAF sensor and o2 voltage tomorrow but I’m not seeing anything out of the ordinary.

Any help will be appreciated.

I had this code and it was a big split in the hose that goes from the air filter to the throttle body. I cured it temporarily with some gaffer tape but it needs another hose. I’ve one off eBay for £15 posted. Hope your cure is as simple as mine.

Thanks , I have checked that and still nothing.

With the code erased at idle readings are:

Short fuel trim 3 - 15% constantly fluctuating

Long fuel trim 20.3% solid
RPM 830

MAF (g/s) 2.4 jumps up to 5 when I rev the engine to 3000rmp

O2 bank 1 sensor 1: 0.1 - 0.9
O2 bank 1 sensor 2: 0.0 (resistance is ok and voltage it ok when metered with a multi meter)

Can anyone help out here? On the Audi TT forum I follow there is a huge section on the software problems with good support.
On here there is nothing much.
I suspect it is because the Japanese do it better, but, when it goes wrong you are on your own?
You may need dedicated Mazda software. I’m not sure if this is available. On my Foxwell. I can add Mazda to my device I use on my Volvo but I’m not sure it giving me much for the £70 they want.