Multiple outputs to COSM?

Hi there,

I was wondering if it was possible to output multiple values to COSM.

What I’m trying to do is post temp, moisture levels, battery charge status and if the water valve is on/off (1 or 0).

I have it currently posting the water valve status and that is working fine.

I’m receiving this data via software serial from an Arduino in the field.

I just have multiple OutputPorts and they individually post to cosm. From my pool controller, I post 5 things to cosm (water temp, air temp, pump speed, salt levels, heater on/off).

can you post your code?

How do I link the different outputs to the different COSM nodes?

Maybe this is what you’re looking for?

awesome… thanks for that! I’ll give that a shot

Hi guys,

I got all the capture stuff working. But I use the array method and its connected to 1 COSM node. It has a status of 200 and it was posting data before ok.

I tired using the array to post but its not posting the data to COSM

`function pollUart()
{
imp.wakeup(0.00001, pollUart.bindenv(this)); // schedule the next poll in 10us

local byte = hardware.uart57.read();    // read the UART buffer
local tempValue = "";
local tempValue2 = "";
local strLen = 0;

// This will return -1 if there is no data to be read.
while (byte != -1)  // otherwise, we keep reading until there is no data to be read.
{
    server.log(format("%c", byte)); // send the character out to the server log. Optional, great for debugging
    //if (byte < 50) //only display if 1 or 0
    //{
        
        tempValue += format("%c", byte);
        
       // server.show(format("%c", byte)); //show value for degubbing [old code]
        //impeeOutput.set(format("%c", byte));  // send the valid character out the impee's outputPort  [old code]
    //}
    byte = hardware.uart57.read();  // read from the UART buffer again (not sure if it's a valid character yet  
}
if (byte == -1) {
 if (tempValue != "") {
        
        tempValue2 = format("%c", tempValue[1]); //skip carrage return and read in values
        strLen = tempValue.len(); //get value for slice
        
        if (strLen > 1) { //only do if valid data
             //check for values before posting
            if (tempValue2 == "w") {
                if (strLen > 5) { //only post if valid data
                
                    impeeOutput[1].set(tempValue.slice(5,strLen)); //moisture level

                    if (tempValue[3] == "0") {
                         server.show("Water is off");
                         impeeOutput.set(format("%c", tempValue[3]));
                    }
                    else if (tempValue[3] == "1") {
                        server.show("Water is on");
                        impeeOutput.set(format("%c", tempValue[3]));
                    }

                    server.show("Water valve: " + format("%c", tempValue[3]));
                    server.show("Moisture level: " + tempValue.slice(5,strLen));
                    
                }
            }
            else if (tempValue2 == "t") {
                 impeeOutput[2].set(tempValue.slice(3,strLen));
                 server.show("Temperature: " + tempValue.slice(3,strLen));
            }
            else if (tempValue2 == "c") {
                impeeOutput[3].set(tempValue.slice(3,strLen));
                server.show("Battery charge status: " + tempValue.slice(3,strLen));
            }
            else {                
             server.show("Did  not match: " + tempValue2);
            }
        }

        tempValue = ""; 
        tempValue2 = "";
    }
}

}`

I’m I missing something? Do I have do something on the planner view?

Here is the setup as well

local impeeInput = impeeIn(); // assign impeeIn class to the impeeInput
local impeeOutput = [ OutputPort(“UART In”, “string”), OutputPort(“Moisture”, “string”), OutputPort(“Temperature”, “string”), OutputPort(“BatteryStatus”, “string”)]; // set impeeOutput as a string

function initUart()
{
hardware.configure(UART_57); // Using UART on pins 5 and 7
hardware.uart57.configure(19200, 8, PARITY_NONE, 1, NO_CTSRTS); // 19200 baud worked well, no parity, 1 stop bit, 8 data bits
}

imp.configure(“UartCrossAir”, [impeeInput], [impeeOutput]);

One thing I can see: you are building impeeOutput as an array, and then making that array an element in the imp.configure array.

Really, this should be:

imp.configure(“UartCrossAir”, [impeeInput], impeeOutput)

…or for neatness, add [] around the single impeeIn() instantiation and then no square brackets in imp.configure at all.

You should then see 4 choices when you drag a noodle from the imp to the cosm block, one for each of your outputs.

awesome!! that worked a treat! thanks for your help… that was the last step in my project :smiley:

Hi murkh. I’m trying to do the same thing with a weather station, and having trouble figuring out formatting the string going out from the Arduino, and in turn, in from the Imp. I am a real newbie.

Would you mind posting your arduino code?