Current Lua downloadable firmware will be posted here

User avatar
By Thomas Jakober
#86390 Hi all
I wanted to find the current altitude for my device for the BME280 to calculate the correct sea level pressure. I used to find this by calling some od the various api's available online which can be called with a http get command. However currently most of these need to be called using https. One of them worked both http as well as https. With http I get the correct answer but all calls with https end up with an error "HTTP client: Connection timeout" even if I installed the tls module.
Does this need some initialisation? DoI need a certificate?

I saw there was a problem back in 2018 but I could not find out wether it has been solved then.

This is my code:
Code: Select all      http.get('https://ipinfo.io/json', nil, function(status, body, headers)
         if status < 0 then
            transmit.log('Failed to get the IP Location')
            return
         end
         print(body)
         local gl = sjson.decode(body)
         transmit.log('The device is in '..gl.city..', '..gl.country)
         http.get('http://api.opentopodata.org/v1/eudem25m?locations='..gl.loc, nil, function(status, body, headers)
            if status < 0 then
               transmit.log('Could not get the altitude')
               return
            end
            file.putcontents('geolocation.json', body)
            local alt = sjson.decode(body)
            transmit.log('Devices altitude is: ', alt[1].elevation)
            file.putcontents('altitude.json', body)
            service[1].altitude = math.floor(alt[1].elevation)
            timer:start()

         end)
      end)


This is my freshly built NodeMCU:
NodeMCU 3.0.0.0 built on nodemcu-build.com provided by frightanic.com
branch: master
commit: 3d917850180f67adc7f2c6b5d00f27c152e7194c
release:
release DTS: 202002231746
SSL: true
build type: float
LFS: 0x20000
modules: adc,bit,bme280,crypto,encoder,file,gpio,http,i2c,mdns,net,node,ow,rtctime,sjson,tmr,uart,websocket,wifi,tls
build 2020-04-06 18:07 powered by Lua 5.1.4 on SDK 3.0.1-dev(fce080e)