transitioning to reactor based gRPC server

main
KeeganForelight 2 years ago
parent 4367f88c07
commit ec160cd2d8

@ -1,3 +1,4 @@
## Weekly Planning
[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
// config
Config *viper.Viper
// gRPC server
pb.UnimplementedDeviceServer
}
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
dm := NewDeviceManager(bus, addr, config, defaultName)
m.SetDeviceManager(dm)
// setting up gRPC server functionality
return m, err
}

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

@ -3,29 +3,40 @@ package grpc;
option go_package = "internal/pkg/grpc";
service deviceInfo {
// serves basic device information
// used by both controllers/sensors
service device {
// groups basic device interactions
// 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 {
int32 Address = 1;
string Name = 2;
service sensor {
// sensor specific functions
rpc Reading(ReadingRequest) returns (ReadingResponse)
rpc SampleRate(SampleRateRequest) returns (SampleRateResponse)
}
enum Status {
DEAD = 0;
ALIVE = 1;
UNKNOWN = 2;
message ReadingRequest {
// empty
}
message DeviceStatus {
int32 addr = 1;
Status status = 2;
message ReadingResponse {
string Reading = 1; // formatted reading "9.7 pH"
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 {
uint32 clientId = 1;
string clientType = 2;
string ip = 3; // client ip
uint32 port = 4; // client port for gRPC server
}
message ClientResponse {

Loading…
Cancel
Save