Weather kit send and receive, logging with openLog inconsistent results

I used the Sparkfun examples as a starting point. I could not get the example to work.

I added an the gator-RTC and a DYI .96 OLED, plus the OpenLog on the Receive Microbit weather.

The Send Weatherbit only has the Full kit set of sensors period.

I set up the serial logging which does write to the micro SD card, however, I often get multiple log files per session.

What can cause the logger to start a new logfile?

I especially noticed not only multiple log file but incomplete data per data request from the sender.

I took the send and receive camping but left the wind, rain, soil temp and soil moisture sensors at home.

Was that the reason for the logging issue? If so, why

Which example are you trying to make work specifically, can you provide a link?

I have not finished trying to patch together all the snapshots so here is the javascript equivalent

Edited by moderator to add code tags. (Please use code tags!)

enum RadioMessage {
    ack = 20929,
    message1 = 49434
}
/**
 * Note: The wind direction is a string. We are not able to save the string as a number. For consistency, we will be using the same string and number pair to send data. Therefore, we will assign a number to each of the directions. If we are in an unknown state "???", we will send a value of 0.
 * 
 * https://learn.sparkfun.com/tutorials/wireless-remote-weather-station-with-microbit/experiment-5-real-time-wireless-data-logging
 * 
 * MOISTURE
 * 
 * Soil Moisture The Soil Moisture block returns an analog value range of 0 - 1023 (a 10 bit number). The lower the number is the less moisture the sensor detects. The "dryness" and "wetness" level depends on your climate, humidity, etc. so we cannot give you a concrete range of what is wet and dry, that is something you will have to fiddle with yourself.
 */
/**
 * 1)  €Date,Time,
 * 
 * 2)  BME280 Temp degC, (/100)
 * 
 * 3)  BME280 Humidity [rH], (/1024)
 * 
 * 4)  BME280 Pressure [hPa], (/25,600 )
 * 
 * 5)  BME280 Altitude [m],
 * 
 * 6)  Rain [in],
 * 
 * 7)  Wind Speed [mph],
 * 
 * 8)  Wind Direction,
 * 
 * 9)  Soil Moisture,
 * 
 * 10) Soil Temp [degC]
 * 
 * NOTE: hPa is  hectopascal
 * 
 * 1 inches of mercury? 3386.3886666667 pascals in one inch Hg
 */
/**
 * iVeiwOLED=1
 * 
 * TM:nn       HUM: nn
 * 
 * PR:nnn::      Rain: nn
 * 
 * WS:nnn      WDIR: nnn
 * 
 * iViewOLED = 2
 * 
 * SM: nn  sT: nn
 */
function getHeader () {
    sHeader = "Date" + "," + "Time" + "," + "BME280 Temp degC" + "," + "BME280 Humidity [rH]" + "," + "BME280 Pressure [hPa]" + "," + "BME280 Altitude [m]" + "," + "Rain [in]" + "," + "Wind Speed [mph]" + "," + "Wind Direction" + "," + "Soil Moisture" + "," + "Soil Temp [degC]"
}
// Clear flag by emptying the array
input.onButtonPressed(Button.A, function () {
    if (!(bView1OLED) && !(bView2OLED)) {
        bView1OLED = true
        OLED12864_I2C.on()
        // "A" pressed  - view Part 2 (dos)
        basic.showLeds(`
            # # . . .
            # # . . .
            # . # . #
            # . # . #
            . . # # #
            `)
    } else if (bView1OLED && !(bView2OLED)) {
        bView1OLED = false
        bView2OLED = true
        OLED12864_I2C.on()
        // "A" pressed  - view Part 2 (dos)
        basic.showLeds(`
            # # . . .
            # # . . #
            # . . . #
            # . . # #
            . . . # #
            `)
        OLED12864_I2C.clear()
    } else if (!(bView1OLED) && bView2OLED) {
        bView1OLED = false
        bView2OLED = false
        OLED12864_I2C.clear()
        OLED12864_I2C.off()
        // Start over
        basic.showLeds(`
            . . . . .
            # # . . #
            # . # . #
            # . . # #
            # . . . #
            `)
    }
    basic.pause(100)
})
function myOLED (showTxt: string, xLoc: number, yLoc: number, iView: number, bView1OLED: boolean, bView2OLED: boolean) {
    if (bView1OLED && iView == 1) {
        OLED12864_I2C.showString(
        xLoc,
        yLoc,
        showTxt,
        1
        )
    } else if (bView2OLED && iView == 2) {
        OLED12864_I2C.showString(
        xLoc,
        yLoc,
        showTxt,
        1
        )
    } else {
        basic.pause(100)
    }
}
function getDateTime () {
    sMyDate = ""
    sMonth = MonthArray[gatorRTC.getTimeComponent(TimeType.Month) - 1]
    basic.pause(100)
    sDay = convertToText(gatorRTC.getTimeComponent(TimeType.Date))
    iLength = sDay.length
    if (iLength == 1) {
        sDay = "0" + sDay
    }
    sMyDate = "0" + sDay
    basic.pause(100)
    sHours = convertToText(gatorRTC.getTimeComponent(TimeType.Hours))
    sMinutes = convertToText(gatorRTC.getTimeComponent(TimeType.Minutes))
    sSeconds = convertToText(gatorRTC.getTimeComponent(TimeType.Seconds))
    iLength = sMinutes.length
    if (iLength == 1) {
        sMinutes = "0" + sMinutes
    }
    iLength = sSeconds.length
    if (iLength > 2) {
        sSeconds = sSeconds.substr(0, 1)
    }
    sTime = "" + sHours + sMinutes + sSeconds
    sDateTime = "" + sMonth + sDay + ":" + sTime
}
radio.onReceivedValue(function (name, value) {
    if (item > 9) {
        item = 0
    }
    item += 1
    basic.pause(100)
    getDateTime()
    myOLED(sDateTime, 0, 0, 1, bView1OLED, bView2OLED)
    basic.pause(100)
    if (name == "time") {
        basic.pause(100)
    } else if (name == "tmpC") {
        tempFH = value * 1.8 + 32
        textDisplay(tempFH, 1)
        sTempC = sReturn
        myOLED("TP:" + sTempC, 0, 1, 1, bView1OLED, bView2OLED)
        serial.writeString("" + sTempC + ",")
    } else if (name == "humidity") {
        iOHumid = value
        textDisplay(iOHumid, 1)
        sHumidity = sReturn
        myOLED("HU:" + sHumidity, xOLED, 1, 1, bView1OLED, bView2OLED)
        serial.writeString("" + sHumidity + ",")
    } else if (name == "pressure") {
        oPressure = value / 3386
        oPressure = oPressure * 100
        textDisplay(oPressure, 1)
        sPressure = sReturn
        myOLED("PR:" + sPressure, 0, 2, 1, bView1OLED, bView2OLED)
        serial.writeString("" + sPressure + ",")
    } else if (name == "altitude") {
        serial.writeString("" + convertToText(value) + ",")
    } else if (name == "rain") {
        textDisplay(value, 1)
        sRain = sReturn
        myOLED("RN:" + sRain, xOLED, 2, 1, bView1OLED, bView2OLED)
        serial.writeString("" + sRain + ",")
    } else if (name == "wind spe") {
        textDisplay(value, 1)
        sWindSpeed = sReturn
        myOLED("WS:" + sWindSpeed, 0, 3, 1, bView1OLED, bView2OLED)
        serial.writeString("" + sWindSpeed + ",")
    } else if (name == "wind dir") {
        sWinDir = lWinDir[value]
        serial.writeString("" + sWinDir + ",")
        sWinDir = "WD:" + sWinDir
        myOLED(sWinDir, xOLED, 3, 1, bView1OLED, bView2OLED)
    } else if (name == "soilMstr") {
        textDisplay(value, 1)
        sSoilMoisture = sReturn
        serial.writeString("" + sSoilMoisture + ",")
        myOLED("SM:" + sSoilMoisture, 0, 2, 2, bView1OLED, bView2OLED)
    } else if (name == "soilTmpC") {
        soilTempF = value * 1.8 + 32
        textDisplay(soilTempF, 1)
        sSoilTemp = sReturn
        myOLED("ST:" + sSoilTemp, xOLED, 2, 2, bView1OLED, bView2OLED)
        serial.writeString("" + sSoilTemp + ",")
        serial.writeLine("")
    }
    basic.showLeds(`
        . . . . .
        . . . . .
        . . # . .
        . . . . .
        . . . . .
        `)
    basic.pause(100)
    basic.clearScreen()
})
// 0 digits after decimal nnn (no decimal)
// if iDigits = 0 then default is 1st 3 char.
// if iDigits = 1 then deciaml plus 2 characters
function textDisplay (iRawVal: number, iDigits: number) {
    let aValue: string[] = []
    sString = convertToText(iRawVal)
    iLength = sString.length
    idxString = sString.indexOf(".")
    if (idxString < 0) {
        aValue.insertAt(0, sString.substr(0, iLength))
        aValue.insertAt(1, sString.substr(0, iLength))
        sReturn = sString.substr(0, iLength)
    } else {
        aValue.insertAt(0, sString.substr(0, idxString - 1))
        sReturn = sString.substr(0, idxString)
        if (iRawVal < 1) {
            sReturn = sString.substr(idxString, iLength - (idxString + 1))
            aValue.insertAt(1, sString.substr(idxString, iLength - (idxString + 1)))
        }
    }
    return sReturn
}
let insideHumid = 0
let insideTemp = 0
let iRowCnt = 0
let idxString = 0
let sString = ""
let sSoilTemp = ""
let soilTempF = 0
let sSoilMoisture = ""
let sWinDir = ""
let sWindSpeed = ""
let sRain = ""
let sPressure = ""
let oPressure = 0
let sHumidity = ""
let iOHumid = 0
let sReturn = ""
let sTempC = ""
let tempFH = 0
let item = 0
let sTime = ""
let sSeconds = ""
let sMinutes = ""
let sHours = ""
let iLength = 0
let sDay = ""
let sMyDate = ""
let sMonth = ""
let sHeader = ""
let MonthArray: string[] = []
let lWinDir: string[] = []
let bView2OLED = false
let bView1OLED = false
let xOLED = 0
let sDateTime = ""
radio.setGroup(37)
let Interval = 30000
let viewOLED = 0
// 23 characters wide
// 4 Lines
// Color: 0 or 1
// x, X alis position, 0 - 63 in zoom mode, 0 - 127 in normal mode.
// y, Y alis position, 0 - 31 in zoom mode, 0 - 63 in normal mode.
// color, draw color, it can be 1 or 0.Zoom == True - readable
// Zoom == False - tiny
OLED12864_I2C.init(60)
basic.pause(100)
OLED12864_I2C.zoom(true)
// Inside Temp
weatherbit.startWeatherMonitoring()
let Set_RTC = 1
sDateTime = "date"
if (Set_RTC == 1) {
    gatorRTC.set1224Mode(TimeMode.Military)
    gatorRTC.set24Time(18, 0, 0)
    gatorRTC.setDate(
    dayNames.Tuesday,
    Months.October,
    6,
    20
    )
}
serial.redirect(
SerialPin.P15,
SerialPin.P14,
BaudRate.BaudRate9600
)
xOLED = 7
bView1OLED = false
bView2OLED = false
sDateTime = ""
lWinDir = ["N ", "NE", "E ", "SE", "SE", "SW", "W ", "NW", "??"]
MonthArray = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C"]
basic.pause(100)
serial.writeString(sHeader)
getDateTime()
serial.writeString(sDateTime)
sMonth = MonthArray[gatorRTC.getTimeComponent(TimeType.Month) - 1]
let iMonth = gatorRTC.getTimeComponent(TimeType.Seconds)
// iViewOLED = 2
// 
// SM: nn  sT: nn  Row=1
// 
// IT:nn   IH:nn   Row=2
// 
// iVeiwOLED=1
// 
// TM:nn       HUM: nn
// 
// PR:nnn::      Rain: nn
// 
// WS:nnn      WDIR: nnn
basic.forever(function () {
    radio.sendValue("Request", 1)
    iRowCnt += 1
    if (iRowCnt > 999999) {
        iRowCnt = 1
    }
    getDateTime()
    myOLED(sDateTime, 0, 0, 2, bView1OLED, bView2OLED)
    insideTemp = weatherbit.temperature() / 100
    insideTemp = insideTemp * 1.8 + 32
    textDisplay(insideTemp, 1)
    myOLED("IT:" + sReturn, 0, 1, 2, bView1OLED, bView2OLED)
    basic.pause(100)
    insideHumid = weatherbit.humidity() / 1024
    textDisplay(insideHumid, 1)
    myOLED("IH:" + sReturn, xOLED, 1, 2, bView1OLED, bView2OLED)
    basic.pause(Interval)
}

Are you fully writing this in Javascript or are you writing this in Arduino?

I am using the Blocks makercode. Due to the length of the blocks (even after refining the code) it is too long to fit in a usable snapshot.

By the way, I do not know what “code tags” are.

If it’s doing multiple logging or missing logging events then I would suspect that it would have to do with an issue with any loops or conditional statements in your code. Unfortunately, it is difficult for us to troubleshoot MakerCode. Furthermore, we can’t offer support for custom code or code outside of our hookup guides.

Thanks.

For future reference: I would like to know what and how to use the “code tags”.

So what is considered “Sparkfun hookup guides” following exactly the example(s) provided?

The reason I wrote my own code was due to the problems I had with the example in the tutorial. I did use the code as a template.

Unfortunately, I entered the example code and the following are some observations:

I typed the Receive and Send program as posted on

https://learn.sparkfun.com/tutorials/wi … ta-logging

I was not able to get the code in the Tutorial to work as it was. It is possible I made some typos, although I did double check one extra time.

My issues with the code:

  1. Write to SD Card Problem

The program only put the header on the SD Card.

If Debug is “1” Then it will write to USB – NOT SD Card

There are 2 possible fixes.

The easiest fix is to change the code in the ON START for Debug == 1 to instead write to the SD Card

Or Change the IF structure such that the Write_Data is checked last so that the SD Card is written to

OR

What I did was change all the Debug(s) to Write_Data and Set Write_Data == 1 :: as I did not think of the switching the “where to write section”

The next problem was that only one “Row” or 1 Data Set was written putting the FOREVER Block into an infinite loop doing nothing.

It is possible that I typed something wrong

I did notice that the IF Interval only executes once as it resides in the “START BLOCK”

I took the IF Block and put it into a FUNCTION BLOCK but I still ran into problems after many iterations.

I purchased a 3V OLED and hooked it to the Microbit, which is how I determined the above issues.

https://makecode.microbit.org/pkg/makec … d12864_i2c

Just one thought on the code tags request. I can’t see the history of the first post, but I would wager that you copy/pasted your code right in when you made the forum post. A moderator probably added ```

 tags
``` such as the ones found here: [app.php/help/bbcode](https://forum.sparkfun.com/app.php/help/bbcode), under "Outputting code or fixed width data "

Thank you for providing that link.