HTTPS with TLS and the X509 cert

I am trying to get HTTPS working as the website doesn’t support HTTP so followed the sample for TLS and the client sample in the documentation section of the website. What I am unsure of is where I should get the cert for this. Do I get this from the website I am trying to connect to? The sample is for google.com

I exported the cert for ecowitt.net and added this to the resources and added the code to add the cert and set the HttpsAuthenCerts to the cert. I get the following from the website:

    #### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (3) ####
    #### Message: 
    #### GHIElectronics.TinyCLR.Devices.Network.Provider.NetworkControllerApiWrapper::AuthenticateAsClient [IP: 0000] ####
    #### System.Net.Security.SslStream::AuthenticateAsClient [IP: 0016] ####
    #### System.Net.Security.SslStream::AuthenticateAsClient [IP: 0009] ####
    #### System.Net.Security.SslStream::AuthenticateAsClient [IP: 0008] ####
    #### System.Net.HttpWebRequest::EstablishConnection [IP: 0251] ####
    #### System.Net.HttpWebRequest::SubmitRequest [IP: 0019] ####
    #### System.Net.HttpWebRequest::GetResponse [IP: 000c] ####
    #### TinyCLRClockLCD7.WeatherDataClass::FetchWeatherDataLocal [IP: 005a] ####
    #### TinyCLRClockLCD7.Program::wifiBackgroundThreadHandler [IP: 004e] ####

If I try to use just HTTP I get this from the server:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<h1>301 Moved Permanently</h1>
<p>The requested resource has been assigned a new permanent URI.</p>
<hr/>Powered by Tengine</body>
</html>

you need root, not ecowitt.net

Thanks Dat, that worked and I can download the JSON now.

Just need to figure out where this error is coming from:

#### Exception System.Exception - 0x00000000 (3) ####
#### Message: unsupported escape

This was the JSON reply:

{"code":0,"msg":"success","time":"1745588126","data":{"outdoor":{"temperature":{"time":"1745588094","unit":"℃","value":"11.9"},"feels_like":{"time":"1745588094","unit":"℃","value":"11.9"},"app_temp":{"time":"1745588094","unit":"℃","value":"11.4"},"dew_point":{"time":"1745588094","unit":"℃","value":"8.0"},"humidity":{"time":"1745588094","unit":"%","value":"77"}},"indoor":{"temperature":{"time":"1745588094","unit":"℃","value":"22.3"},"humidity":{"time":"1745588094","unit":"%","value":"56"}},"solar_and_uvi":{"solar":{"time":"1745588094","unit":"W\/m²","value":"0.0"},"uvi":{"time":"1745588094","unit":"","value":"0"}},"rainfall_piezo":{"rain_rate":{"time":"1745588094","unit":"mm\/hr","value":"0.0"},"daily":{"time":"1745588094","unit":"mm","value":"0.0"},"event":{"time":"1745588094","unit":"mm","value":"0.0"},"hourly":{"time":"1745588094","unit":"mm","value":"0.0"},"weekly":{"time":"1745588094","unit":"mm","value":"0.4"},"monthly":{"time":"1745588094","unit":"mm","value":"0.4"},"yearly":{"time":"1745588094","unit":"mm","value":"0.4"}},"wind":{"wind_speed":{"time":"1745588094","unit":"km\/h","value":"0.0"},"wind_gust":{"time":"1745588094","unit":"km\/h","value":"2.9"},"wind_direction":{"time":"1745588094","unit":"º","value":"23"}},"pressure":{"relative":{"time":"1745588094","unit":"hPa","value":"1023.1"},"absolute":{"time":"1745588094","unit":"hPa","value":"1023.1"}},"lightning":{"count":{"time":"1745588094","unit":"","value":"0"}},"battery":{"haptic_array_battery":{"time":"1745588094","unit":"V","value":"3.16"},"haptic_array_capacitor":{"time":"1745588094","unit":"V","value":"4.3"},"lightning_sensor":{"time":"1745588094","unit":"","value":"5"}}}}

1 Like

I found the issue. There is a / used in some of the fields such as W/m2 so I downloaded the library and rebuilt and included data.JSON and was able to find where it crashed and add it to the library.

Got some work to do now with working out how the JSON decode works.

1 Like