DEV Community

loading...

Discussion on: Get and Store Temperature from a Raspberry Pi with Go

Collapse
devhammed profile image
Hammed Oyedele • Edited

Nice but I am not sure why you are not using LIMIT 10 in getLastTen like this:

 func getLastTen() []Reading {

    // query the database for readings
-    rows, _ := db.Query("SELECT TimeStamp, Temperature, Humidity from reading LIMIT 20")
+    rows, _ := db.Query("SELECT TimeStamp, Temperature, Humidity from reading LIMIT 10")

    // create some temp variables
    var TimeStamp string
    var Temperature float64
    var Humidity float64

    // make a slice
    lastTen := make([]Reading, 10)

    // insert data into slice
    for rows.Next() {
        rows.Scan(&TimeStamp, &Temperature, &Humidity)
        lastTen = append(lastTen, Reading{TimeStamp: TimeStamp, Temperature: Temperature, Humidity: Humidity})
    }
    // return it
    return lastTen
}
Collapse
jeremycmorgan profile image
Jeremy Morgan Author

Ah, yes I took the code from my stream and forgot to change that. Thank you for the feedback!

Forem Open with the Forem app