This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Computer Information: | |
Manufacturer: Apple | |
Model: MacBookPro11,4 | |
Form Factor: Laptop | |
No Touch Input Detected | |
Processor Information: | |
CPU Vendor: GenuineIntel | |
CPU Brand: Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz | |
CPU Family: 0x6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
mqtt "github.com/eclipse/paho.mqtt.golang" | |
) | |
func main() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func SubscribeECU() { | |
Client.Subscribe("ingest/ecu", 0, func(client mqtt.Client, msg mqtt.Message) { | |
fmt.Println("[MQ] Received ecu message") | |
}) | |
} | |
func SubscribeBattery() { | |
Client.Subscribe("ingest/battery", 0, func(client mqtt.Client, msg mqtt.Message) { | |
fmt.Println("[MQ] Received battery message") | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
ConnectMQTT() | |
SubscribeECU() | |
SubscribeBattery() | |
for {} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"time" | |
) | |
type ECU struct { | |
ID int `json:"id"` | |
MotorRPM int `json:"motor_rpm"` | |
Speed int `json:"speed"` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func ECUFromBytes(data []byte) ECU { | |
var ecu ECU | |
// MotorRPM is bytes 0-1 | |
ecu.MotorRPM = int(binary.BigEndian.Uint16(data[0:2])) | |
// Speed is byte 2 | |
ecu.Speed = int(data[2]) | |
// Throttle is bytes 3-4 | |
ecu.Throttle = int(binary.BigEndian.Uint16(data[3:5])) | |
// BrakePressure is bytes 5-6 | |
ecu.BrakePressure = int(binary.BigEndian.Uint16(data[5:7])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func SubscribeECU() { | |
Client.Subscribe("ingest/ecu", 0, func(client mqtt.Client, msg mqtt.Message) { | |
ecu := ECUFromBytes(msg.Payload()) // add this | |
fmt.Printf("[MQ] Received ecu message: %v\n", ecu) | |
}) | |
} | |
func SubscribeBattery() { | |
Client.Subscribe("ingest/battery", 0, func(client mqtt.Client, msg mqtt.Message) { | |
battery := BatteryFromBytes(msg.Payload()) // add this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"gorm.io/driver/mysql" | |
"gorm.io/gorm" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
ConnectMQTT() | |
SubscribeECU() | |
SubscribeBattery() | |
ConnectDB() // add this | |
for { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ECU struct { | |
ID int `json:"id" gorm:"primaryKey"` // add this | |
MotorRPM int `json:"motor_rpm"` | |
Speed int `json:"speed"` | |
Throttle int `json:"throttle"` | |
BrakePressure int `json:"brake_pressure"` | |
CreatedAt time.Time `json:"created_at" gorm:"precision:6"` // add this | |
} | |
type Battery struct { |
OlderNewer