Closed wengjjpaul closed 7 years ago
Okay i think i found the issue. I have to add these functions to ino file
void before() {
}
void presentation() {
}
void receive(McMessage &message) {
}
void receiveTime(unsigned long) {
}
@wengjjpaul Yes, you are right. I am sorry this time I do not have document for this library!
My temperature sensor code:
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
#include <MyController.h>
#define RELAY_PIN 0
#define SEN_TEMP "temp_sensor"
#define SEN_SWITCH "switch"
#define SEN_MEASURMENT "volt"
#define SEN_MEMORY "memory"
MyController mc;
unsigned long lastRun;
uint16_t seconds = 0;
void sendTemperature(){
sensors.requestTemperatures(); // Send the command to get temperatures
McMessage _message;
_message.update(SEN_TEMP, C_SET, V_TEMP);
send(_message.set(sensors.getTempCByIndex(0), 3));
}
void sendVolatage(){
McMessage _message;
_message.update(SEN_MEASURMENT, C_SET, V_VOLTAGE);
send(_message.set(ESP.getVcc()));
}
void sendFreeHeap(){
McMessage _message;
_message.update(SEN_MEMORY, C_SET, V_FREE);
send(_message.set(ESP.getFreeHeap()));
}
void sendMeasurments(){
sendTemperature();
sendVolatage();
sendFreeHeap();
}
void setup() {
//set GPIO 0 as output pin
pinMode(RELAY_PIN, OUTPUT);
//hwWriteConfig(EEPROM_INTERNAL_SYSTEM_RESET, 0x00);
if(!isSystemConfigured()){
MC_SERIAL.printf("MC: System not configured...user input needed\n");
}
// Start up the sensors library
sensors.begin();
lastRun = millis();
}
void before(){
sendMeasurments();
}
void presentation(){
sendSketchInfo("Remote device", "1.0.0");
present(S_TEMP, SEN_TEMP, "Temperature sensor");
present(S_BINARY, SEN_SWITCH, "Switch");
present(S_MULTIMETER, SEN_MEASURMENT, "Voltage");
present(S_MEMORY, SEN_MEMORY, "Memory");
request(SEN_TEMP, V_TEMP);
request(SEN_SWITCH, V_STATUS);
request(SEN_MEASURMENT, V_VOLTAGE);
request(SEN_MEMORY, V_FREE);
}
void receive(McMessage &message) {
if(message.isSubTypeOf(V_STATUS)){
digitalWrite(RELAY_PIN, message.getBool());
}else{
MC_SERIAL.printf("MC: Not supported message >> ");
message.printOnSerial();
}
}
void receiveTime(unsigned long timestamp){
MC_SERIAL.printf("MC: Timestamp received:%d\n", timestamp);
}
void loop() {
mc.loop();
if((millis() - lastRun) > 1000){
lastRun = millis();
seconds++;
}
//2 minutes job, send RSSI, Properties/Statistics
if(seconds >= 2*60){
seconds = 0;
sendMeasurments();
}
}
I tried to use this library on wemos arduino. I added initialise() in setup function. I added loop() in the loop function. Would be great is there is a small example on how to use this library.
ets Jan 8 2013,rst cause:4, boot mode:(3,6)
wdt reset load 0x4010f000, len 1384, room 16 tail 8 chksum 0x2d csum 0x2d v3de0c112 ~ld