transitioning to reactor based gRPC server

main
KeeganForelight 2 years ago
parent 4367f88c07
commit ec160cd2d8

@ -1,3 +1,4 @@
## Weekly Planning ## Weekly Planning
[Jan 16-20](weekly/Jan-16-20.md) [Jan 16-20](weekly/Jan-16-20.md)
[Jan 23-27](weekly/Jan-23-27.md)

@ -0,0 +1,29 @@
# Jan 23
### Connecting Clients to reactors
**Client -> Server -> Reactor**
I can take advantage of the private network created via wireguard to allow the server to connected back to individual reactors and then intiate gRPC calls.
**Pros**
- This *VASTLY* simplifies the implementation as I can now connect back to the reactors themselves
- from there, I can implement various functions I will need server side
- i.e. GetName() SetName() etc.
**Cons**
- I will eventually need to build the wiregaurd implementation
- although because its all local network for now, I can plug and play down the road
### TODO
- refactor packages to provide a cleaner interface via simple commands as opposed to the convoluted passing structure that was present with the old I2C library
- start working on the interface between the websocket and the reactor
- react side this is the actual content that will be rendered by the client
- server side this will be a connection to a reactor with the gRPC calls
- moving monitoring functionality to the reactor
- refactoring to use streaming functionality to avoid needing to re initiate request
- have server connect each reactor manager to the rlc
- have the reactor manager ping for server info
- handle disconnects via exit
- sets up cleaner device handling via multiplexing

@ -36,6 +36,8 @@ type DeviceManager struct {
Manager Manager
// config // config
Config *viper.Viper Config *viper.Viper
// gRPC server
pb.UnimplementedDeviceServer
} }
func NewDeviceManager(bus, addr int, config *viper.Viper, defaultName string) *DeviceManager { func NewDeviceManager(bus, addr int, config *viper.Viper, defaultName string) *DeviceManager {

@ -44,5 +44,7 @@ func New(bus, addr int, config *viper.Viper) (Device, error) {
// setting device manager // setting device manager
dm := NewDeviceManager(bus, addr, config, defaultName) dm := NewDeviceManager(bus, addr, config, defaultName)
m.SetDeviceManager(dm) m.SetDeviceManager(dm)
// setting up gRPC server functionality
return m, err return m, err
} }

@ -13,8 +13,12 @@ type SensorManager struct {
// sampling // sampling
sampleMu sync.RWMutex sampleMu sync.RWMutex
LatestSample float32 LatestSample float32
SampleTimestamp int64
*DeviceManager `mapstructure:",squash"` *DeviceManager `mapstructure:",squash"`
// gRPC server
pb.UnimplementedSensorServer
} }
func NewSensorManager() *SensorManager { func NewSensorManager() *SensorManager {
@ -82,6 +86,7 @@ func (s *SensorManager) Monitor(f takeReading) {
fmt.Printf("Got %f\n", reading) fmt.Printf("Got %f\n", reading)
s.sampleMu.Lock() s.sampleMu.Lock()
s.LatestSample = float32(reading) s.LatestSample = float32(reading)
s.SampleTimestamp = time.Now.Unix()
s.sampleMu.Unlock() s.sampleMu.Unlock()
} }
} }

@ -3,29 +3,40 @@ package grpc;
option go_package = "internal/pkg/grpc"; option go_package = "internal/pkg/grpc";
service deviceInfo { service device {
// serves basic device information // groups basic device interactions
// used by both controllers/sensors // get/set name based on request
rpc Name(NameRequest) returns (NameResponse)
}
rpc DeviceName(stream DeviceName) returns (stream DeviceName); message NameRequest {
// empty for future expansion
string Name = 1;
}
rpc DeviceStatus(stream DeviceStatus) returns (stream DeviceStatus); message NameResponse {
string Name = 1;
} }
message DeviceName { service sensor {
int32 Address = 1; // sensor specific functions
string Name = 2; rpc Reading(ReadingRequest) returns (ReadingResponse)
rpc SampleRate(SampleRateRequest) returns (SampleRateResponse)
} }
enum Status { message ReadingRequest {
DEAD = 0; // empty
ALIVE = 1;
UNKNOWN = 2;
} }
message DeviceStatus { message ReadingResponse {
int32 addr = 1; string Reading = 1; // formatted reading "9.7 pH"
Status status = 2; int64 Timestamp = 2; // when the reading was taken
} }
message SampleRateRequest {
int32 SampleRate = 1; // 0 to return current sample rate, value in seconds
}
message SampleRateResponse {
int32 SampleRate = 1; // returns the set sample rate
}

@ -10,6 +10,8 @@ service handshake {
message ClientRequest { message ClientRequest {
uint32 clientId = 1; uint32 clientId = 1;
string clientType = 2; string clientType = 2;
string ip = 3; // client ip
uint32 port = 4; // client port for gRPC server
} }
message ClientResponse { message ClientResponse {

Loading…
Cancel
Save