Keith Barker marked his return to Warwickshire with a match-winning wicket-haul as Essex were defeated by 41 runs in a gripping Rothesay County Championship Division One match at Edgbaston.