Instantly share code, notes, and snippets.

@vicngtor /manager.ino Secret
Created Oct 7, 2014

Embed
What would you like to do?
#include <SPI.h>
#include <Wire.h>
#include <Scout.h>
#include <GS.h>
#include <bitlash.h>
#include <lwm.h>
#include <js0n.h>
#include <Oyoroi.h>
#define INPUT_BUFFER_SIZE 20
char inputdata[INPUT_BUFFER_SIZE];
byte input_bytes_received=0;
void setup() {
Scout.setup("Custom", "Null", -1);
Serial.begin(115200);
Shell.isVerbose = true;
Shell.eval("rm *");
addBitlashFunction("oyoroi.print", (bitlash_function) oyoroiPrint);
// We do not care about arg(1) which is the scoutId
Shell.eval("function on.message.group { oyoroi.print(arg(1), arg(2), arg(3)) }");
//Shell.eval("mesh.config(1, 57, 20)");
Shell.eval("mesh.joingroup(58)");
}
void loop() {
Scout.loop();
}
void sendToMotes(char *message) {
char command[130]; // 20 + max message length
sprintf(command, "message.group(58, \"%s\")", message);
Serial.println(command);
Serial.flush();
Shell.eval(command);
}
numvar oyoroiPrint(void) {
Serial.println(keyGet(getarg(3)));
}
void serialEvent() {
if(Serial.available() > 0){
input_bytes_received=Serial.readBytesUntil(13,inputdata,INPUT_BUFFER_SIZE);
inputdata[input_bytes_received]=0;
sendToMotes(inputdata);
}
}
#include <SPI.h>
#include <Wire.h>
#include <Scout.h>
#include <GS.h>
#include <bitlash.h>
#include <lwm.h>
#include <js0n.h>
#include <Oyoroi.h>
#define INPUT_BUFFER_SIZE 20
#define OUTPUT_BUFFER_SIZE 20
boolean input_stringcomplete = false;
boolean sensor_stringcomplete = false;
byte sensor_bytes_received=0;
byte input_bytes_received=0;
char inputdata[INPUT_BUFFER_SIZE];
char sensordata[OUTPUT_BUFFER_SIZE];
byte received_from_computer=0;
byte serial_event=0;
byte code=0;
char ec_data[48];
byte in_char=0;
void setup() {
Scout.setup("Custom", "Null", -1);
Serial.begin(115200);
Serial1.begin(38400);
Serial1.print("C,0");
Serial1.print("\r");
Serial1.flush();
Shell.isVerbose = true;
Shell.eval("rm *");
addBitlashFunction("oyoroi.receive", (bitlash_function) oyoroiReceive);
Shell.eval("function on.message.group { oyoroi.receive(arg(1), arg(2), arg(3)) }");
//Shell.eval("mesh.config(2, 57, 20)"); // Scouts are ALWAYS id=2, troopId=3
Shell.eval("mesh.joingroup(58)");
}
void loop() {
Scout.loop();
if(Serial1.available() > 0){
sensor_bytes_received=Serial1.readBytesUntil(13,sensordata,OUTPUT_BUFFER_SIZE);
sensordata[sensor_bytes_received]=0;
char temp[100];
sprintf(temp, "serial=%lu|data=%s",
Scout.getHwSerial(), sensordata);
sendToManager(temp);
}
}
void sendToManager(char *message) {
char command[120]; // 20 + max message length
sprintf(command, "message.group(58, \"%s\")", message);
Serial.println(command);
Serial.flush();
Shell.eval(command);
}
numvar oyoroiReceive(void) {
if (getarg(2) == 1) {
Serial.print("Scout received from Manager: ");
Serial.println(keyGet(getarg(3))); // debug
Serial1.print(keyGet(getarg(3)));
Serial1.print("\r");
Serial1.flush();
} else {
Serial.print(getarg(1));
Serial.print(' ');
Serial.print(getarg(2));
Serial.print(' ');
Serial.print(keyGet(getarg(3)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment