During the First World War Hartley was commissioned into the Royal Flying Corps as a second lieutenant on 23 August 1916, and became a qualified pilot. He was promoted lieutenant on 22 February 1918. He ended the war with the rank of major. During the war Hartley joined the armaments section of the Air Board, working with Bertram Hopkinson. He was responsible for the Air Board's development of George Constantinescu's interrupter gear which allowed a machine gun to be fired through the propeller blades of an aircraft without danger of damage. This invention was said by Air Vice Marshal Sir John Maitland to be responsible for air superiority over German aircraft. He transferred to the Royal Air Force on its establishment as a separate service. He was appointed an Officer of the Order of the British Empire on 10 October 1919 in recognition of his war work.
Interbellum
After the war Hartley worked as a consulting engineer for five years before joining the Anglo-Persian Oil Company in 1924 as assistant manager of its engineering division. He became assistant manager of the supply department later the same year and from 1932 to 1934 he was seconded to the Iraq Petroleum Company, on his return being appointed chief engineer. The company became the Anglo-Iranian Oil Company in 1935.
Following the outbreak of the Second World War Hartley was seconded from Anglo-Iranian to the Ministry of Aircraft Production in 1940. From 1940-1 he assisted with the development of a stabilized bombsight which was used by RAF Bomber Command in the sinking of the German battleshipTirpitz in 1944. From 1942 Hartley worked with the Petroleum Warfare Department and was appointed as its technical director. Here he developed, at the request of Air Chief MarshalArthur Harris, the Fog Investigation and Dispersal Operation which was known as FIDO. This was a means of burning oil along runways to disperse fog. The system was installed at fifteen airfields across Britain, beginning in 1943. FIDO is credited with bringing 2,500 aircraft and 10,000 aircrew safely home during the war. Hartley also developed the pipes used in Operation Pluto, a series of twenty-one undersea pipes used to transport oil from Britain to continental Europe to support the Liberation of Europe. The system supplied the allied armies with of fuel per day during the advance into Germany, and Hartley received £9000 after the war for his work on Pluto from the Royal Commission on Awards to Inventors. He also received an appointment as Commander of the Order of the British Empire in 1944.
Post-war
Hartley was awarded the United StatesMedal of Freedom in 1946. He retired from Anglo-Iranian in 1951 and became an engineering consultant during which time he developed the Hartley hoister – a device which allowed the loading of oil tankers offshore. He was elected president of the Institution of Mechanical Engineers in 1951 and was an honorary fellow of the City and Guilds of London Institute. He was also made an honorary fellow of Imperial College London in 1953. In 1959 he received the Redwood Medal of the Institute of Petroleum. He was elected president of the Institution of Civil Engineers in 1959. However he died just three months into his term at St Thomas's Hospital, London on 28 January 1960.
Personal life
Hartley married Dorothy Elizabeth Wallace, the daughter of a Shanghai-based marine engineer, in 1920 and had two sons. Dorothy died in 1923, and in 1927 he married Florence Nina Hodgson with whom he had a further two sons.