Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

HTTPS HTTPput


Jason@ Oct 3, 2024 07:27 PM

Ola, 

Having some issues with a program and the HTTPPut command. I'll paste the relevant part of the program below (edited for space). but basically I've got a datalogger with 5 tables that I need pushed (put) to an HTTPS address. I've been given an authentication code but keep getting a 401 error. Also the errors populate in the http_header variable not in the "http_Put_Response" variable. 

 

'Declare Variables and Units
Public BattV                 : Units BattV = volts
Public PTemp_C               : Units PTemp_C = °C
Public PTemp_F               : Units PTemp_F = °F



Public CVData(14)
Public SlrTF_MJ              : Units SlrTF_MJ = MJ/m²
Public CVMeta As String * 40
Public WSpdPrev              : Units WSpdPrev = miles/hour
Public WindDirPrev           : Units WindDirPrev = degrees
Public MaxWSpdPrev           : Units MaxWSpdPrev = miles/hour
Public Invalid_Wind As Long
Public http_header As String * 200
Public http_put_response1 As String * 200
Public http_put_response2 As String * 200
Public http_put_response3 As String * 200
Public http_put_response4 As String * 200
Public http_put_response5 As String * 200
Public SERVER_PATH As String *250
Public http_put_tx1
Public http_put_tx2
Public http_put_tx3
Public http_put_tx4
Public http_put_tx5

Alias CVData(1) = SlrFD_W                 : Units SlrFD_W = W/m²
Alias CVData(2) = Rain                    : Units Rain = inches
Alias CVData(3) = Strikes                 : Units Strikes = count
Alias CVData(4) = Distance                : Units Distance = miles
Alias CVData(5) = WindSpd                 : Units WindSpd = miles/hour
Alias CVData(6) = WindDir                 : Units WindDir = °
Alias CVData(7) = MaxWindSpd              : Units MaxWindSpd = miles/hour
Alias CVData(8) = AirTemperature          : Units AirTemperature = °F
Alias CVData(9) = Vapor_Press             : Units Vapor_Press = mbar
Alias CVData(10) = Barometric_Press       : Units Barometric_Press = mbar
Alias CVData(11) = Relative_Humidity      : Units Relative_Humidity = %
Alias CVData(12) = Relative_Humidity_Temp : Units Relative_Humidity_Temp = °F
Alias CVData(13) = TiltNS_deg             : Units TiltNS_deg = °
Alias CVData(14) = TiltWE_deg             : Units TiltWE_deg = °


Public CollectData(3) As Boolean
Public Result_AC(3) As Long

Public Accel_AC1(3)
Alias Accel_AC1(1) = Accel_1x
Alias Accel_AC1(2) = Accel_1y
Alias Accel_AC1(3) = Accel_1z

Public Accel_AC2(3)
Alias Accel_AC2(1) = Accel_2x
Alias Accel_AC2(2) = Accel_2y
Alias Accel_AC2(3) = Accel_2z

Public Accel_AC3(3)
Alias Accel_AC3(1) = Accel_3x
Alias Accel_AC3(2) = Accel_3y
Alias Accel_AC3(3) = Accel_3z

Dim i


'Define Data Tables
DataTable(CT_Wx,True,-1)
  DataInterval(0,10,Min,10)
  Minimum(1,BattV,FP2,False,False)
  Sample(1,PTemp_C,FP2)
  Sample(1,SlrFD_W,IEEE4)
  Average(1,SlrFD_W,IEEE4,False)
  Minimum(1,SlrFD_W,IEEE4,False,True)
  Maximum(1,SlrFD_W,IEEE4,False,True)
  Totalize(1,Rain,IEEE4,False)
  Totalize(1,Strikes,FP2,False)
  Minimum(1,Distance,FP2,False,True)
  Maximum(1,Distance,FP2,False,False)
  Sample(1,WindSpd,FP2)
  Sample(1,WindDir,FP2)
  WindVector(1,WindSpd,WindDir,FP2,False,90,0,0)
  FieldNames("WS_ms_S_WVT,WindDir_D1_WVT,WindDir_SD1_WVT")
  Maximum(1,MaxWindSpd,FP2,False,False)
  Sample(1,AirTemperature,FP2)
  Average(1,AirTemperature,FP2,False)
  Minimum(1,AirTemperature,FP2,False,True)
  Maximum(1,AirTemperature,FP2,False,True)
  Sample(1,Vapor_Press,IEEE4)
  Sample(1,Barometric_Press,IEEE4)
  StdDev(1,Barometric_Press,IEEE4,False)
  Sample(1,Relative_Humidity,FP2)
  Sample(1,Relative_Humidity_Temp,FP2)
  StdDev(1,Relative_Humidity_Temp,FP2,False)
  Sample(1,TiltNS_deg,FP2)
  Sample(1,TiltWE_deg,FP2)
  Totalize(1,SlrTF_MJ,IEEE4,False)
EndTable


'Accelerometer Data
DataTable(CT_AC1,True,-1)
  Sample(3,Accel_AC1(),IEEE4)
EndTable

DataTable(CT_AC2,True,-1)
  Sample(3,Accel_AC2(),IEEE4)
EndTable

DataTable(CT_AC3,True,-1)
  Sample(3,Accel_AC3(),IEEE4)
EndTable



DataTable(Daily_Data,True,-1)
  DataInterval(86390,86400,Sec,10)
  Minimum(1,BattV,FP2,False,False)
  Minimum(1,PTemp_C,FP2,False,True)
  Maximum(1,PTemp_C,FP2,False,True)
  Maximum(1,SlrFD_W,FP2,False,True)
  Totalize(1,Rain,FP2,False)
  Minimum(1,Distance,FP2,False,True)
  Average(1,WindSpd,FP2,False)
  WindVector(1,WindSpd,WindDir,FP2,False,90,0,0)
  FieldNames("WindSpd_S_WVT,WindDir_D1_WVT,WindDir_SD1_WVT")
  Maximum(1,MaxWindSpd,FP2,False,True)
  Minimum(1,AirTemperature,FP2,False,True)
  Maximum(1,AirTemperature,FP2,False,True)
  Minimum(1,Vapor_Press,IEEE4,False,True)
  Maximum(1,Vapor_Press,IEEE4,False,True)
  Minimum(1,Barometric_Press,IEEE4,False,True)
  Maximum(1,Barometric_Press,IEEE4,False,True)
  Minimum(1,Relative_Humidity,FP2,False,True)
  Maximum(1,Relative_Humidity,FP2,False,True)
  Totalize(1,Invalid_Wind,FP2,False)
  Sample(1,CVMeta,String)
EndTable



'Main Program
BeginProg

  SetSetting("StationName", "CT_Wx")


  'apply power to the ClimaVUE50
  SW12 (SW12_1,1 )
  http_header = "Internal file tag"&CHR(13)&CHR(10)&"internat logger tag"  
  SERVER_PATH = "https://altitude.stantec.com/func/api/RunCampbellScientificFunction?code=Authorization code"
  'If the datalogger program has just started running, delay program execution for ten seconds to allow the ClimaVUE50 time to warm up
  Delay(0,10,Sec)


  'Main Scan
  Scan(10,Sec,1,0)

    'Default CR6 Datalogger Battery Voltage measurement 'BattV'
    Battery(BattV)

    'Default CR6 Datalogger Wiring Panel Temperature measurement 'PTemp_C'
    PanelTemp(PTemp_C,60)
    PTemp_F = PTemp_C * 1.8 + 32

    'ClimaVUE50 Compact Digital Weather Sensor measurements
    'SlrFD_W', 'Rain', 'Strikes', 'Distance', 'WindSpd', 'WindDir',
    'MaxWindSpd', 'AirTemperature', 'Vapor_Press', Barometric_Press', 'Relative_Humidity', 'Relative_HumidityT_F',
    'TiltNS_deg', and 'TiltWE_deg'
    'Get data from ClimaVUE50 Compact Digital Weather Sensor
    SDI12Recorder(CVData(),C1,"0","R7!",1,0,-1)

    'Convert fractional relative humidity into percent relative humidity
    Relative_Humidity = Relative_Humidity*100

    'Calculate total solar flux in MJ/m² from flux density in W/m²
    'The multiplier to calculate total flux was calculated by Short Cut
    'and based on a program execution rate (scan rate) of 10 Seconds.
    'If you change the program execution rate outside of Short Cut with the CRBasic Editor
    'you will need to recalculate this multiplier. See the sensor manual for more details.
    SlrTF_MJ = SlrFD_W*1E-05

    'Convert rain in mm to inch
    Rain = Rain * 0.03937

    'Convert average strike distance in kilometers to miles
    Distance = Distance * 0.621371

    'Convert wind speed in meters/second to miles/hour
    WindSpd = WindSpd * 2.23694

    'Convert maximum wind speed in meters/second to miles/hour
    MaxWindSpd = MaxWindSpd * 2.23694

    'Convert air temperature in °C to °F
    AirTemperature = AirTemperature * 1.8 + 32

    'Convert vapor pressure in kPa to mbar
    Vapor_Press = Vapor_Press * 10

    'Convert barometric pressure in kPa to mbar
    Barometric_Press = Barometric_Press * 10

    'Convert relative humidity sensor temperature in °C to °F
    Relative_Humidity_Temp = Relative_Humidity_Temp * 1.8 + 32

    'High winds with rain can temporarily interfere with sonic wind measurements causing the sensor to output -9999 or -9990. The following instructions set invalid wind measurements
    'to the previous valid wind measurements. This will 'flat-line' the measurements until the sensor is able to make good readings again. The Invalid_Wind variable will be set to 1 when
    'a wind measurement is invalid. For troubleshooting purposes, it is highly recommended that you totalize the Invalid_Wind variable in any output tables you define that include
    'wind speed and/or direction data from the ClimaVUE50.
    If WindSpd < 0 Then
      WindSpd = WSpdPrev
      WindDir = WindDirPrev
      MaxWindSpd = MaxWSpdPrev
      Invalid_Wind = 1
    Else
      WSpdPrev = WindSpd
      WindDirPrev = WindDir
      MaxWSpdPrev = MaxWindSpd
      Invalid_Wind = 0
    EndIf

    'Get ClimaVUE50 Compact Digital Weather Sensor metadata 'CVMeta' every day at midnight in case sensor is swapped or OS is updated
    If IfTime(0,1,Day) Then
      SDI12Recorder(CVMeta,C1,"0","I!",1,0)
    EndIf



    'Call Data Tables and Store Data
    CallTable CT_Wx
    CallTable Daily_Data


    'set remote stations clock to match base station
    If TimeIntoInterval (0,1430,Min)
      ClockReport (COMRF,0,1)
      ClockReport (COMRF,0,2)
      ClockReport (COMRF,0,3)
    EndIf


  NextScan



  SlowSequence
  Scan (1,Min,3,0)

    If IfTime (2,10,Min) Then
      For i = 1 To 3
        CollectData(i) = True
      Next i
    EndIf


    If CollectData(1) Then
      GetDataRecord (Result_AC(1),COMRF,0,1,0,0.05,4,32769,CT_AC1,-1)
      If Result_AC(1) = 0 Then CollectData(1) = false
    EndIf

    If CollectData(2) Then
      GetDataRecord (Result_AC(2),COMRF,0,2,0,0.05,4,32769,CT_AC2,-1)
      If Result_AC(2) = 0 Then CollectData(2) = false
    EndIf

    If CollectData(3) Then
      GetDataRecord (Result_AC(3),COMRF,0,3,0,0.05,4,32769,CT_AC3,-1)
      If Result_AC(3) = 0 Then CollectData(3) = false
    EndIf
  If IfTime (5,10,min)Then
  http_put_tx1 = HTTPPut (SERVER_PATH,"CT_Wx",http_put_response1,http_header,0,10,min,-1008,7500)
  Delay (1,30,Sec)
  http_put_tx2 = HTTPPut (SERVER_PATH,"Daily_Data",http_put_response2,http_header,0,10,min,-1008,7500)
  Delay (1,30,Sec)
  http_put_tx3 = HTTPPut (SERVER_PATH,"CT_AC1",http_put_response3,http_header,0,10,min,-1008,7500)
  Delay (1,30,Sec)
  http_put_tx4 = HTTPPut (SERVER_PATH,"CT_AC2",http_put_response4,http_header,0,10,min,-1008,7500)
    Delay (1,30,Sec)
  http_put_tx5 = HTTPPut (SERVER_PATH,"CT_AC3",http_put_response5,http_header,0,10,min,-1008,7500)
    EndIf
  NextScan
EndProg

 Main thing is I need to know if I'm doing something wrong with the HTTPPut command?

Also, should I be putting the server_path and http_header in as constants? Actually I've already done that, but when I did I couldn't get any error codes to pop up in the http_put_response variables.

Also because i'm sending data from 5 tables should I (as I did) break it up into 5 seperate commands? or is there a way to do it all in one?

 

 


borisalvarado Oct 16, 2024 03:20 AM

This post is under review.

Log in or register to post/reply in the forum.