@@ -46,6 +46,58 @@ func kickCheck(chkicker chan bool) {
4646
4747func main () {
4848
49+ //Hostnameを取得する
50+ cmd := exec .Command ("hostname" )
51+ out , err := cmd .Output ()
52+ if err != nil {
53+ panic (err )
54+ }
55+ fmt .Println (string (out ))
56+
57+ //もし初期値のraspberrypiだったら
58+ if string (out ) == "raspberrypi\n " {
59+ //UNIX時間の下5桁を取得する
60+ unixtime := time .Now ().UnixNano ()
61+ log .Println ("Unixtime is " + fmt .Sprintf ("%d" , unixtime ))
62+ unixtime = unixtime % 100000
63+
64+ //Hostnameをracoon-XXXXXに変更する
65+ hostname := "racoon-" + fmt .Sprintf ("%05d" , unixtime )
66+
67+ log .Println ("Change Hostname To " + hostname )
68+ //Change Hostname
69+ //hostnamectl set-hostname raspberrypi コマンド実行
70+ cmd = exec .Command ("hostnamectl" , "set-hostname" , hostname )
71+ cmd .Run ()
72+
73+ //hostsの変更
74+ cmd = exec .Command ("sudo" , "sed" , "-i" , "/etc/hosts" , "-e" , "s/raspberrypi/" + hostname + "/g" , "/etc/hosts" )
75+ cmd .Run ()
76+
77+ //再起動
78+ log .Println ("=====Reboot=====" )
79+
80+ buzzer := rpio .Pin (12 )
81+ buzzer .Mode (rpio .Pwm )
82+ buzzer .Freq (1175 * 64 )
83+ buzzer .DutyCycle (16 , 32 )
84+ time .Sleep (500 * time .Millisecond )
85+ buzzer .DutyCycle (0 , 32 )
86+ buzzer .Freq (1396 * 64 )
87+ buzzer .DutyCycle (16 , 32 )
88+ time .Sleep (500 * time .Millisecond )
89+ buzzer .DutyCycle (0 , 32 )
90+ buzzer .Freq (1760 * 64 )
91+ buzzer .DutyCycle (16 , 32 )
92+ time .Sleep (500 * time .Millisecond )
93+ buzzer .DutyCycle (0 , 32 )
94+
95+ //reboot コマンド実行
96+ cmd = exec .Command ("reboot" )
97+ cmd .Run ()
98+
99+ }
100+
49101 //自動アップデート
50102 go confirmAndSelfUpdate ()
51103 //GPIOの初期化
@@ -101,58 +153,6 @@ func main() {
101153 }
102154 }()
103155
104- //Hostnameを取得する
105- cmd := exec .Command ("hostname" )
106- out , err := cmd .Output ()
107- if err != nil {
108- panic (err )
109- }
110- fmt .Println (string (out ))
111-
112- //もし初期値のraspberrypiだったら
113- if string (out ) == "raspberrypi\n " {
114- //UNIX時間の下5桁を取得する
115- unixtime := time .Now ().UnixNano ()
116- log .Println ("Unixtime is " + fmt .Sprintf ("%d" , unixtime ))
117- unixtime = unixtime % 100000
118-
119- //Hostnameをracoon-XXXXXに変更する
120- hostname := "racoon-" + fmt .Sprintf ("%05d" , unixtime )
121-
122- log .Println ("Change Hostname To " + hostname )
123- //Change Hostname
124- //hostnamectl set-hostname raspberrypi コマンド実行
125- cmd = exec .Command ("hostnamectl" , "set-hostname" , hostname )
126- cmd .Run ()
127-
128- //hostsの変更
129- cmd = exec .Command ("sudo" , "sed" , "-i" , "/etc/hosts" , "-e" , "s/raspberrypi/" + hostname + "/g" , "/etc/hosts" )
130- cmd .Run ()
131-
132- //再起動
133- log .Println ("=====Reboot=====" )
134-
135- buzzer := rpio .Pin (12 )
136- buzzer .Mode (rpio .Pwm )
137- buzzer .Freq (1175 * 64 )
138- buzzer .DutyCycle (16 , 32 )
139- time .Sleep (500 * time .Millisecond )
140- buzzer .DutyCycle (0 , 32 )
141- buzzer .Freq (1396 * 64 )
142- buzzer .DutyCycle (16 , 32 )
143- time .Sleep (500 * time .Millisecond )
144- buzzer .DutyCycle (0 , 32 )
145- buzzer .Freq (1760 * 64 )
146- buzzer .DutyCycle (16 , 32 )
147- time .Sleep (500 * time .Millisecond )
148- buzzer .DutyCycle (0 , 32 )
149-
150- //reboot コマンド実行
151- cmd = exec .Command ("reboot" )
152- cmd .Run ()
153-
154- }
155-
156156 //MyIDで指定したロボットIDを取得
157157 var MyID uint32 = uint32 (diptoid )
158158
0 commit comments