From dd8ee0fa7d7ff35a7ae63173ae9020f62c378b47 Mon Sep 17 00:00:00 2001 From: Scott Frazer Date: Wed, 19 Nov 2025 14:46:35 -0500 Subject: [PATCH] deploy: latest from hub --- note/session.go | 16 ++++++++++++++++ note/usage.go | 2 ++ notecard/i2c-unix.go | 1 - notecard/i2c-windows.go | 1 - notecard/request.go | 1 + notecard/serial-unix.go | 1 - notecard/serial-windows.go | 1 - notehub/api/fleet.go | 13 +++++++++++-- notehub/auth.go | 25 +++++++++++++++++++------ notehub/request.go | 9 +++++++++ 10 files changed, 58 insertions(+), 12 deletions(-) diff --git a/note/session.go b/note/session.go index a9d3998..81a352a 100644 --- a/note/session.go +++ b/note/session.go @@ -10,6 +10,8 @@ type DeviceSession struct { SessionUID string `json:"session,omitempty"` // When the session was initially opened SessionBegan int64 `json:"session_began,omitempty"` + // When a persistent session was last updated + SessionUpdated int64 `json:"session_updated,omitempty"` // Why a session was opened WhySessionOpened string `json:"why_session_opened,omitempty"` // When the session was initially opened @@ -80,6 +82,8 @@ type DeviceSession struct { HighPowerCyclesTotal uint32 `json:"hp_cycles_total,omitempty"` HighPowerCyclesData uint32 `json:"hp_cycles_data,omitempty"` HighPowerCyclesGPS uint32 `json:"hp_cycles_gps,omitempty"` + // Amount of packet usage within the session, keyed by PSID + PacketUsage map[string]PacketUsage `json:"packet_usage,omitempty"` // Total device usage at the beginning of the period ThisPtr *DeviceUsage `json:"this,omitempty"` // Total device usage at the beginning of the next period, whenever it happens to occur @@ -123,6 +127,18 @@ func (s *DeviceSession) Period() *DeviceUsage { return s.PeriodPtr } +// Indication of the packet usage within a session +type PacketUsage struct { + Updated int64 `json:"updated,omitempty"` + DownlinkPackets int64 `json:"dl_p,omitempty"` + DownlinkBytes int64 `json:"dl_b,omitempty"` + DownlinkBytesBillable int64 `json:"dl_bb,omitempty"` + UplinkPackets int64 `json:"ul_p,omitempty"` + UplinkBytes int64 `json:"ul_b,omitempty"` + UplinkBytesBillable int64 `json:"ul_bb,omitempty"` + BillableMinBytesPerPacket int64 `json:"bmbpp,omitempty"` +} + // TowerLocation is a location structure generated by a lookup type TowerLocation struct { Source string `json:"source,omitempty"` // source of this location diff --git a/note/usage.go b/note/usage.go index 3b23c25..8c2ff82 100644 --- a/note/usage.go +++ b/note/usage.go @@ -14,6 +14,8 @@ type DeviceUsage struct { SentBytesSecondary uint32 `json:"bytes_sent_secondary,omitempty"` TCPSessions uint32 `json:"sessions_tcp,omitempty"` TLSSessions uint32 `json:"sessions_tls,omitempty"` + PacketSessions uint32 `json:"sessions_packet,omitempty"` + WebhookSessions uint32 `json:"sessions_webhook,omitempty"` RcvdNotes uint32 `json:"notes_rcvd,omitempty"` SentNotes uint32 `json:"notes_sent,omitempty"` } diff --git a/notecard/i2c-unix.go b/notecard/i2c-unix.go index f27ba40..7820c6a 100644 --- a/notecard/i2c-unix.go +++ b/notecard/i2c-unix.go @@ -5,7 +5,6 @@ // Forked from github.com/davecheney/i2c //go:build !windows -// +build !windows // Before usage you must load the i2c-dev kernel module. // Each i2c bus can address 127 independent i2c devices, and most diff --git a/notecard/i2c-windows.go b/notecard/i2c-windows.go index acb478f..3cea9dc 100644 --- a/notecard/i2c-windows.go +++ b/notecard/i2c-windows.go @@ -3,7 +3,6 @@ // copyright holder including that found in the LICENSE file. //go:build windows -// +build windows package notecard diff --git a/notecard/request.go b/notecard/request.go index 4c92238..706a9de 100644 --- a/notecard/request.go +++ b/notecard/request.go @@ -479,6 +479,7 @@ type Request struct { Voltage float64 `json:"voltage,omitempty"` MilliampHours float64 `json:"milliamp_hours,omitempty"` Default bool `json:"default,omitempty"` + In bool `json:"in,omitempty"` } // A Note on Time diff --git a/notecard/serial-unix.go b/notecard/serial-unix.go index 9ff2b32..c1c7de7 100644 --- a/notecard/serial-unix.go +++ b/notecard/serial-unix.go @@ -3,7 +3,6 @@ // copyright holder including that found in the LICENSE file. //go:build !windows -// +build !windows package notecard diff --git a/notecard/serial-windows.go b/notecard/serial-windows.go index fb3bd22..770871c 100644 --- a/notecard/serial-windows.go +++ b/notecard/serial-windows.go @@ -3,7 +3,6 @@ // copyright holder including that found in the LICENSE file. //go:build windows -// +build windows // If you have odd serial port behavior (where responses are apparently lost or delayed), try this: // 1) open Control Panel -> Device Manager -> Ports (COM & LPT) diff --git a/notehub/api/fleet.go b/notehub/api/fleet.go index 17cd61d..df389ac 100644 --- a/notehub/api/fleet.go +++ b/notehub/api/fleet.go @@ -18,8 +18,9 @@ type FleetResponse struct { EnvironmentVariables map[string]string `json:"environment_variables"` - SmartRule string `json:"smart_rule,omitempty"` - WatchdogMins int64 `json:"watchdog_mins,omitempty"` + SmartRule string `json:"smart_rule,omitempty"` + WatchdogMins int64 `json:"watchdog_mins,omitempty"` + ConnectivityAssurance FleetConnectivityAssurance `json:"connectivity_assurance,omitempty"` } // PutDeviceFleetsRequest v1 @@ -67,3 +68,11 @@ type PutFleetRequest struct { SmartRule string `json:"smart_rule,omitempty"` WatchdogMins int64 `json:"watchdog_mins,omitempty"` } + +// FleetConnectivityAssurance v1 +// +// Includes, Enabled = Whether Connectivity Assurance is enabled for this fleet +// With flexibility to add more information in the future +type FleetConnectivityAssurance struct { + Enabled bool `json:"enabled"` +} diff --git a/notehub/auth.go b/notehub/auth.go index 2d3723a..18dea81 100644 --- a/notehub/auth.go +++ b/notehub/auth.go @@ -103,10 +103,21 @@ func RevokeAccessToken(hub, token string) error { // InitiateBrowserBasedLogin starts the OAuth2 login flow by opening the user's browser. // the `hub` parameter is the hostname of Notehub where it is assumed that an OAuth2 client // with client ID `notehub_cli` is configured for authorization code flow. -func InitiateBrowserBasedLogin(hub string) (*AccessToken, error) { +func InitiateBrowserBasedLogin(notehubApiHost string) (*AccessToken, error) { // this is the hard-coded OAuth client ID that's persisted in Hydra clientId := "notehub_cli" + if !strings.HasPrefix(notehubApiHost, "api.") { + notehubApiHost = "api." + notehubApiHost + } + + var notehubUiHost string + if notehubApiHost == "api.notefile.net" { + notehubUiHost = "notehub.io" + } else { + notehubUiHost = strings.TrimPrefix(notehubApiHost, "api.") + } + // Try these ports in order until one is available: // // these ports are randomly chosen and hard-coded into @@ -157,7 +168,7 @@ func InitiateBrowserBasedLogin(hub string) (*AccessToken, error) { tokenResp, err := http.Post( (&url.URL{ Scheme: "https", - Host: hub, + Host: notehubUiHost, Path: "/oauth2/token", }).String(), "application/x-www-form-urlencoded", @@ -217,7 +228,7 @@ func InitiateBrowserBasedLogin(hub string) (*AccessToken, error) { // Get user's information (specifically email) /////////////////////////////////////////// - req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://%s/userinfo", hub), nil) + req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("https://%s/userinfo", notehubApiHost), nil) if err != nil { errHandler("could not create request for /userinfo: " + err.Error()) return @@ -253,7 +264,7 @@ func InitiateBrowserBasedLogin(hub string) (*AccessToken, error) { /////////////////////////////////////////// accessToken = &AccessToken{ - Host: hub, + Host: notehubApiHost, Email: email, AccessToken: accessTokenString, ExpiresAt: time.Now().Add(expiresIn), @@ -304,7 +315,7 @@ func InitiateBrowserBasedLogin(hub string) (*AccessToken, error) { // Build the authorize URL using the chosen port authorizeUrl := url.URL{ Scheme: "https", - Host: hub, + Host: notehubUiHost, Path: "/oauth2/auth", RawQuery: url.Values{ "client_id": {clientId}, @@ -319,7 +330,9 @@ func InitiateBrowserBasedLogin(hub string) (*AccessToken, error) { // Open web browser to authorize fmt.Printf("Opening web browser to initiate authentication (redirect port %d)...\n", chosenPort) - open(authorizeUrl.String()) + if err := open(authorizeUrl.String()); err != nil { + fmt.Printf("error opening web browser: %v", err) + } // Wait for exchange to finish <-done diff --git a/notehub/request.go b/notehub/request.go index 2d7cd20..e3b43ea 100644 --- a/notehub/request.go +++ b/notehub/request.go @@ -17,6 +17,15 @@ import ( // HubDeviceContact (golint) const HubDeviceContact = "hub.device.contact" +// HubDeviceSessionBegin (golint) +const HubDeviceSessionBegin = "hub.device.session.begin" + +// HubDeviceSessionUsage (golint) +const HubDeviceSessionUsage = "hub.device.session.usage" + +// HubDeviceSessionEnd (golint) +const HubDeviceSessionEnd = "hub.device.session.end" + // HubAppGetSchemas (golint) const HubAppGetSchemas = "hub.app.schemas.get"