Query Slower after Rows Deleted
ANALYZE TABLE .. may refresh the statistics such that queries run faster.  (Defragging (OPTIMIZE TABLE) takes a long time and is probably overkill.)
For future purging, implement PARTITION BY RANGE; see this for discussion.
The first query would be faster if the ORDER BY said the same thing as the GROUP BY.
Instead of AND DATE(TimeStamp) = @D1, say AND Timestamp &gt;= @D1 AND Timestamp &lt; @D1 + INTERVAL 1 DAY, plus have composite INDEX(IMEI, Timestamp).  (The index you have is not as efficient for this query.)
innodb_buffer_pool_size should be somewhere around 70% of RAM.  Increasing it too much will lead to swapping, which is terrible for performance.