gohome icon indicating copy to clipboard operation
gohome copied to clipboard

automata.yaml missing?

Open SonnyWalkman opened this issue 1 year ago • 3 comments

Hello @Barnybug, I'm looking on how to implement a repeater controller using gofsm and having states and transition in automata.yml file. Finding hard to understand how gohome uses it. great work on gohome btw.

// The automata are configured via yaml configuration format configured under: // // http://localhost:8723/config?path=gohome/config/automata

SonnyWalkman avatar Aug 28 '23 04:08 SonnyWalkman

Hi, thanks for looking at my project! It's more just a hobby project that I put up on github for posterity than something supported/documented (as you've probably found!), but you're welcome to run it!

There's a couple of examples of config here, though may be slight out of date: https://github.com/barnybug/gohome/blob/c491aeb4b31c86c12f0a23c07ea27e40bcb5d082/config.yml#L4 https://github.com/barnybug/gohome/blob/c491aeb4b31c86c12f0a23c07ea27e40bcb5d082/config/config_test.go#L6

barnybug avatar Aug 31 '23 13:08 barnybug

You need to upload the config to a topic on the mqtt server - there's a command: gohome config config config.yml But I've not tested starting a 'greenfield' installation from nothing, so YMMV!

barnybug avatar Aug 31 '23 13:08 barnybug

Hey Barnaby Gray,

I've put a few things together however I think I've missed something? I'm new to Go coming from Python. Go is Great! I'm coding up a repeater which is like a TV transmitter. number of states with transitions.Thought using fsm is a better approach than a bunch of nested if else's?

My Go code main.go

package main

import ( "fmt" "github.com/barnybug/gofsm" "os" )

func main() { data, err := os.ReadFile("fsm_config.yaml") if err != nil { panic(err) }

// Initialize the FSM from YAML fsm, err := gofsm.FromYaml(data) if err != nil { panic(err) }

// Subscribe to state changes fsm.OnChange(func(e *gofsm.Event) { fmt.Printf("transitioned from %v -> %v by %v\n", e.Src(), e.Dst(), e.Event()) })

// Simulate events fsm.Event("EvtStartupDone") fsm.Event("EvtGoOnAir") fsm.Event("EvtEndTransmission") fsm.Event("EvtSleep") fsm.Event("EvtWakeup") fsm.Event("EvtShutdown") }

My fsm_config.yaml file initial: STARTUP states:

  • STARTUP
  • IDLE
  • ONAIR
  • SHUTDOWN
  • SLEEP events:
  • EvtStartupDone
  • EvtGoOnAir
  • EvtEndTransmission
  • EvtShutdown
  • EvtSleep
  • EvtWakeup transitions: STARTUP: EvtStartupDone: IDLE IDLE: EvtGoOnAir: ONAIR EvtShutdown: SHUTDOWN EvtSleep: SLEEP ONAIR: EvtEndTransmission: IDLE SLEEP: EvtWakeup: IDLE

Any quick clue on how to use it?

Regards

Rob

On Thu, 31 Aug 2023 at 23:16, Barnaby Gray @.***> wrote:

You need to upload the config to a topic on the mqtt server - there's a command: gohome config config config.yml But I've not tested starting a 'greenfield' installation from nothing, so YMMV!

— Reply to this email directly, view it on GitHub https://github.com/barnybug/gohome/issues/9#issuecomment-1701022075, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM4O2SZ6RTJLPLQ3PST3F4DXYCFETANCNFSM6AAAAAA4A2Z5HU . You are receiving this because you authored the thread.Message ID: @.***>

SonnyWalkman avatar Sep 01 '23 01:09 SonnyWalkman