pi/netsender: add net speed test functionality

Issue #36 resolved
Saxon Milton created an issue

This issue is a sub part of issue #31.

We wish to add net speed testing (upload and download) to netsender. Calculation of netspeed would not occur continuously, so it’s proposed that we add a “response code” similar to Reboot, Update and Debug called “Test”. A “Test” button will be placed next to the other mentioned actions on the vidgrind UI in another PR for the vidgrind repo.

We will add a case for “ResponseTest” under the switch that deals with the response code in the Run() method i.e.

// Handle the service response, if any.
    switch rc {
    case ResponseUpdate:
        //...

    case ResponseReboot:
        //...

    case ResponseDebug:
        //...

    case ResponseUpgrade:
        //...

    // ****NEW CODE*****
    case ResponseTest:
        // Test upload using request to /api/test/upload
        // Test download using request to /api/test/download
        // Store results in netsender value fields i.e.
        // ns.upload = blah and ns.download = blah
    // ******************
    }

Calculated upload and download rates will be stored in fields in the netsender struct called upload and download. The next time there is a poll request and input pins and their values are populated, we will check for the pins X0 and X1. If they are there, we can add download and upload values respectively. This code might look like this:

func (ns *Sender) Run() error {
    ns.logger.Log(DebugLevel, debugRunning)

    rc := ResponseNone
    var err error
    var sent bool

    ip := ns.Param("ip")
    if ip != "" {
        pins := MakePins(ip, "")
        if ns.read != nil {
            for i := range pins {

                // ****** NEW CODE *******
                // If a speed test has been done, and we have pins for 
                // download and upload rate specified in config then add values.
                if ns.speedTested {
                    switch pin[i].name {
                    case "X0":
                        pin[i].value = ns.download          
                    case "X1":
                        pin[i].value = ns.upload
                    }
                }
                // ***********************

                err := ns.read(&pins[i])
                if err != nil {
                    ns.logger.Log(WarnLevel, warnPinRead, "error", err.Error(), "pin", pins[i].Name)
                }
            }
        }
        if _, rc, err = ns.Send(RequestPoll, pins); err != nil {
            return err
        }
        sent = true
    }

Comments (2)

  1. Alan Noble

    LGTM.

    This is very similar to what I started implemented for the Arduino on the iot/bandwidth-test branch.

  2. Log in to comment