api

package
v0.0.0-...-9b34752 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2023 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Overview

This package handles all the APIs provided by `wazigate-system`

Index

Constants

View Source
const FAN_PIN = "GPIO5" // PIN #29
View Source
const LED1_PIN = "GPIO27" // PIN #13
View Source
const LED2_PIN = "GPIO22" // PIN #15
View Source
const POWER_IN_PIN = "GPIO23" // PIN #16

The GPIO pin that receives a signal when the main power is cut

View Source
const PWR_BTN = "GPIO26" // PIN #37
View Source
const SHUTDOWN_COUNTDOWN = 3 // for n seconds the button needs to be held down to activate shutdown procedure
View Source
const WiFi_BTN = "GPIO6" // PIN #31
View Source
const WiFi_BTN_COUNTDOWN = 3 // for n seconds the button needs to be held down to revert the wifi/web ui settings

Variables

View Source
var DEBUG_MODE bool //DEBUG mode sends the errors via the HTTP responds
View Source
var ETH_DEVICE string //Ethernet Interface
View Source
var OledBuffer string // A Shared buffer for showing message on the OLED
View Source
var OledCurrentMsg string // The message which is showing on the OLED at the moment
View Source
var PackageJSON []byte // set by main.go
View Source
var WIFI_DEVICE string //Wifi Interface which can be set via env

Functions

func APIDocs

func APIDocs(resp http.ResponseWriter, req *http.Request, params routing.Params)

APIDocs API documents (Swagger)

func ActivateAPMode

func ActivateAPMode() error

Activate Access Point Mode

func BlackoutEnabled

func BlackoutEnabled(resp http.ResponseWriter, req *http.Request, params routing.Params)

This function implements GET /blackout It returns a boolean value indicating whether the Wazigate is equipped with a blackout protection circuit

func CloudAccessible

func CloudAccessible(withLogs bool) bool

Checks if Waziup cloud is accessible

func DeleteNetWiFi

func DeleteNetWiFi(resp http.ResponseWriter, req *http.Request, params routing.Params)

DeleteNetWiFi implements DELETE /net/wifi

func DockerAction

func DockerAction(resp http.ResponseWriter, req *http.Request, params routing.Params)

This function implements POST /docker/:cId/:action It receives typical actions that can be done to a container such as: start, stop, restart

func DockerLogs

func DockerLogs(resp http.ResponseWriter, req *http.Request, params routing.Params)

This function implements GET /docker/:cId/logs It retrieves the logs for a given container Id It can be called this way to receive only the `N` recent logs: `/docker/:cId/logs/:tail`

func DockerStatus

func DockerStatus(resp http.ResponseWriter, req *http.Request, params routing.Params)

This function implements GET /docker

func DockerStatusById

func DockerStatusById(resp http.ResponseWriter, req *http.Request, params routing.Params)

This function implements GET /docker/:cId

func GetGWBootstatus

func GetGWBootstatus(withLogs bool) (bool, string)

This function provides the booting up information to be shown on the OLED

func GetNetInfo

func GetNetInfo(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetNetInfo implements GET /net

func GetNetWiFi

func GetNetWiFi(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetNetWiFi implements GET /net/wifi

func GetRootPath

func GetRootPath() string

This function retrieves the root path of where the binary is being executed

func GetSystemConf

func GetSystemConf(resp http.ResponseWriter, req *http.Request, params routing.Params)

Implements GET /conf

func GetTime

func GetTime(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetTime implements GET /time

func GetTimeZone

func GetTimeZone(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetTimeZone implements GET /timezone

func GetTimeZoneAuto

func GetTimeZoneAuto(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetTimeZoneAuto implements GET /timezone/auto

func GetTimeZones

func GetTimeZones(resp http.ResponseWriter, req *http.Request, params routing.Params)

GetTimeZones implements GET /timezones and provide a list of available timezones

func GoMonitor

func GoMonitor() error
func HomeLink(resp http.ResponseWriter, req *http.Request, params routing.Params)

HomeLink implements GET / Just a test msg to see if it works

func Init

func Init() error

func InternetAccessible

func InternetAccessible(resp http.ResponseWriter, req *http.Request, params routing.Params)

InternetAccessible implements GET /internet

func ListenAndServeHTTP

func ListenAndServeHTTP()

ListenAndServeHTTP serves the APIs and the UI.

func Monitor

func Monitor(messages chan interface{})

func NetConns

func NetConns(resp http.ResponseWriter, req *http.Request, params routing.Params)

Implements GET /net/conns

func NetWiFiScan

func NetWiFiScan(resp http.ResponseWriter, req *http.Request, params routing.Params)

Implements GET /net/wifi/scanning

func OledWriteMessage

func OledWriteMessage(resp http.ResponseWriter, req *http.Request, params routing.Params)

This function implements POST|PUT /oled API

func ResourceUsage

func ResourceUsage(resp http.ResponseWriter, req *http.Request, params routing.Params)

This function implements GET /usage It provides the CPU, RAM and Storage (e.g. Disk) usage

func RunBlackoutManager

func RunBlackoutManager() error

This function monitors the power input in the new boards and check if there is black out then shuts down the gateway

func RunButtonsManager

func RunButtonsManager() error

This function handles the push buttons on WaziHAT

func RunFanManager

func RunFanManager() error

This function is constantly (every 5 seconds) checking the CPU temperature and if it goes beyond the threshold defined in the dahsboard, it triggers the fan

func RunLEDManager

func RunLEDManager() error

This function controlls the LED indicators

func RunOLEDManager

func RunOLEDManager() error

OLED Controller This function gets the gateway status periodically and updates the OLED

func RunTimezoneManager

func RunTimezoneManager() error

This function initializes the timezone configuration and it is called on startup to set the timezone according to the configs

func SSH

func SSH(resp http.ResponseWriter, req *http.Request, params routing.Params)

func SetNetAP

func SetNetAP(resp http.ResponseWriter, req *http.Request, params routing.Params)

Implements POST|PUT /net/wifi/ap

func SetNetAPMode

func SetNetAPMode(resp http.ResponseWriter, req *http.Request, params routing.Params)

implements POST /net/wifi/mode/ap

func SetNetWiFi

func SetNetWiFi(resp http.ResponseWriter, req *http.Request, params routing.Params)

SetNetWiFi implements POST/PUT /net/wifi

func SetSystemConf

func SetSystemConf(resp http.ResponseWriter, req *http.Request, params routing.Params)

Implements POST|PUT /conf

func SetSystemTime

func SetSystemTime(newDate string) error

func SetTime

func SetTime(resp http.ResponseWriter, req *http.Request, params routing.Params)

Implements POST|PUT /time

func SetTimeZone

func SetTimeZone(resp http.ResponseWriter, req *http.Request, params routing.Params)

Implements POST|PUT /timezone

func SocketRequest

func SocketRequest(addr string, url string, method string, contentType string, body io.Reader, withLogs bool) (string, error)

SocketRequest makes a request to a unix socket

func SystemReboot

func SystemReboot(resp http.ResponseWriter, req *http.Request, params routing.Params)

Implements POST|PUT /reboot

func SystemShutdown

func SystemShutdown(resp http.ResponseWriter, req *http.Request, params routing.Params)

Implements POST|PUT /shutdown

func UI

func UI(resp http.ResponseWriter, req *http.Request, params routing.Params)

UI implements HTTP /ui

Types

type AccessPointRequest

type AccessPointRequest struct {
	SSID     string `json:"ssid"`
	Password string `json:"password"`
}

type Configuration

type Configuration struct {
	SetupWizard     bool    `json:"setup_wizard"`
	FanTriggerTemp  float64 `json:"fan_trigger_temp"`  // At which temperature the Fan should start
	OLEDHaltTimeout int     `json:"oled_halt_timeout"` // After what time the OLED goes off
	LocalTimezone   string  `json:"local_timezone"`    // Local time zone
}

Configuration keeps the general config of the settings app

var Config Configuration // the main configuration object

type DeleteWifiReq

type DeleteWifiReq struct {
	SSID string `json:"ssid"`
}

type WifiReq

type WifiReq struct {
	Enabled     bool   `json:"enabled"` // legacy, remove
	SSID        string `json:"ssid"`
	Autoconnect bool   `json:"autoConnect"`
	Password    string `json:"password"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL