This commit is contained in:
Dooho Yi 2021-05-05 12:22:51 +09:00
parent ba8623b286
commit 11e21ba386
5 changed files with 137 additions and 125 deletions

View file

@ -1,30 +1,45 @@
; < NOTE >
; to enable verbose output add option -->
; $ platformio run --verbose
; to make this permanent for the proj. -->
; $ platformio settings set force_verbose Yes
; then confirm the change -->
; $ platformio settings get
; // pio v 4.0 'Build options'
; - build_type
; - build_flags
; - src_build_flags
; - build_unflags
; - src_filter
; - targets
[platformio]
default_envs = nodemcuv2
[env]
framework = arduino
upload_speed = 921600
upload_port =
/dev/ttyUSB0
/dev/tty.SLAB_USBtoUART
lib_deps =
SPI
Wire
64 ; ArduinoJson
1269 ; Painless Mesh
721 ; TaskScheduler
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
lib_deps =
${env.lib_deps}
ESP8266WiFi
Servo(esp8266)
upload_speed = 921600 ; 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
[env:huzzah]
[env:d1_mini_pro]
platform = espressif8266
board = huzzah
board = d1_mini_pro
lib_deps =
${env.lib_deps}
ESP8266WiFi
Servo(esp8266)
upload_speed = 460800 ; 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600

View file

@ -46,114 +46,47 @@
//============</gastank>===========
//============<parameters>============
#define MESH_SSID "forest-all/around"
#define MESH_PASSWORD "cc*vvvv/kkk"
#define MESH_PORT 5555
#define MESH_CHANNEL 5
#define LONELY_TO_DIE (1000)
//============</parameters>===========
//
// LED status indication
// phase 0
// - LED => steady on
// - booted. and running. no connection. scanning.
// phase 1
// - LED => slow blinking (syncronized)
// - + connected.
//
#if defined(ARDUINO_ESP8266_NODEMCU) // nodemcuv2
#define LED_PIN 2
#elif defined(ARDUINO_ESP8266_ESP12) // huzzah
#define LED_PIN 2
#elif defined(ARDUINO_FEATHER_ESP32) // featheresp32
#define LED_PIN 13
#elif defined(ARDUINO_NodeMCU_32S) // nodemcu-32s
#define LED_PIN 2
#endif
#define LED_PERIOD (1111)
#define LED_PERIOD (11111)
#define LED_ONTIME (1)
#define LED_GAPTIME (222)
//
#define WIFI_CHANNEL 5
//
// 'MONITORING_SERIAL'
//
// --> sometimes, the 'Serial' is in use (for example, 'osc' node)
// then, use 'Serial1' - D4/GPIO2/TDX1 @ nodemcu (this is TX only.)
//
// --> otherwise, MONITORING_SERIAL == Serial.
//
#if defined(SERIAL_SWAP)
#define MONITORING_SERIAL (Serial1)
#else
#define MONITORING_SERIAL (Serial)
#endif
//
//============</parameters>===========
//arduino
#include <Arduino.h>
//i2c
#include <Wire.h>
//post & addresses
#include "../../post.h"
//painlessmesh
#include <painlessMesh.h>
painlessMesh mesh;
//espnow
#include <ESP8266WiFi.h>
#include <espnow.h>
//scheduler
//task
#include <TaskScheduler.h>
Scheduler runner;
//task #0 : connection indicator
bool onFlag = false;
bool isConnected = false;
//prototypes
void taskStatusBlink_steadyOn();
void taskStatusBlink_slowblink_insync();
void taskStatusBlink_steadyOff();
//the task
Task statusblinks(0, 1, &taskStatusBlink_steadyOn); // at start, steady on. default == disabled. ==> setup() will enable.
// when disconnected, and trying, steadyon.
void taskStatusBlink_steadyOn() {
onFlag = true;
}
// when connected, blink per 1s. sync-ed. (== default configuration)
void taskStatusBlink_slowblink_insync() {
// toggler
onFlag = !onFlag;
// on-time
statusblinks.delay(LED_ONTIME);
// re-enable & sync.
if (statusblinks.isLastIteration()) {
statusblinks.setIterations(2); //refill iteration counts
statusblinks.enableDelayed(LED_PERIOD - (mesh.getNodeTime() % (LED_PERIOD*1000))/1000); //re-enable with sync-ed delay
}
}
// when connected, steadyoff. (== alternative configuration)
void taskStatusBlink_steadyOff() {
onFlag = false;
}
//task #1 : happy or lonely
// --> automatic reset after some time of 'loneliness (disconnected from any node)'
void nothappyalone() {
static bool isConnected_prev = false;
static unsigned long lonely_time_start = 0;
// oh.. i m lost the signal(==connection)
if (isConnected_prev != isConnected && isConnected == false) {
lonely_time_start = millis();
Serial.println("oh.. i m lost!");
}
// .... how long we've been lonely?
if (isConnected == false) {
if (millis() - lonely_time_start > LONELY_TO_DIE) {
// okay. i m fed up. bye the world.
Serial.println("okay. i m fed up. bye the world.");
Serial.println();
#if defined(ESP8266)
ESP.reset();
#elif defined(ESP32)
ESP.restart();
// esp32 doesn't support 'reset()' yet...
// (restart() is framework-supported, reset() is more forced hardware-reset-action)
#else
#error unknown esp.
#endif
}
}
//
isConnected_prev = isConnected;
}
// Task nothappyalone_task(1000, TASK_FOREVER, &nothappyalone, &runner, true); // by default, ENABLED.
Task nothappyalone_task(100, TASK_FOREVER, &nothappyalone); // by default, ENABLED.
//-*-*-*-*-*-*-*-*-*-*-*-*-
// servo
#define SERVO_PIN D6
#include <Servo.h>
#define SERVO_PIN D6
Servo myservo;
// #define HITTING_ANGLE 87
#define HITTING_ANGLE 90

View file

@ -21,7 +21,7 @@
//============<identities>============
//
#define MY_GROUP_ID (3000)
#define MY_ID (MY_GROUP_ID + 789)
#define MY_ID (MY_GROUP_ID + 122)
#define MY_SIGN ("CRICKET")
//
//============</identities>============

View file

@ -1,5 +1,5 @@
#N canvas 437 95 568 438 12;
#N canvas 78 143 1133 383 roundly 1;
#N canvas 642 89 797 725 12;
#N canvas 200 472 1133 383 roundly 0;
#X msg 364 139 \$1 5000;
#X obj 364 162 unpack f f;
#X obj 364 185 s X1;
@ -7,16 +7,16 @@
#X obj 54 208 r HELLO;
#X obj 54 254 unpack f f f f;
#X floatatom 85 283 5 0 0 0 - - -;
#X obj 107 311 hsl 1000 15 -50000 50000 0 0 empty empty empty -2 -8
0 10 -260097 -262144 -1 0 1;
#X obj 107 331 hsl 1000 15 -50000 50000 0 0 empty empty empty -2 -8
0 10 -13381 -262144 -1 0 1;
#X obj 107 311 hsl 1000 15 -500000 500000 0 0 empty empty empty -2
-8 0 10 -260097 -262144 -1 0 1;
#X obj 107 331 hsl 1000 15 -500000 500000 0 0 empty empty empty -2
-8 0 10 -13381 -262144 -1 0 1;
#X obj 164 254 unpack f f f f;
#X floatatom 195 283 5 0 0 0 - - -;
#X floatatom 263 99 5 0 0 0 target_pos - -;
#X obj 107 31 hsl 1000 15 -50000 50000 0 0 empty empty empty -2 -8
#X obj 107 31 hsl 1000 15 -500000 500000 0 0 empty empty empty -2 -8
0 10 -260097 -262144 -1 49950 1;
#X obj 107 51 hsl 1000 15 -50000 50000 0 0 empty empty empty -2 -8
#X obj 107 51 hsl 1000 15 -500000 500000 0 0 empty empty empty -2 -8
0 10 -13381 -262144 -1 49950 1;
#X obj 263 121 t b a;
#X msg 714 139 \$1 5000;
@ -96,17 +96,81 @@
#X obj 222 204 metro 2000;
#X obj 62 343 s NOTE;
#X obj 222 343 s NOTE;
#X obj 222 238 riff 200 3001;
#X msg 127 157 symbol riff10;
#X msg 287 157 symbol riff11;
#X obj 62 238 riff 170 3120;
#N canvas 0 23 450 278 (subpatch) 0;
#X array riff13 10 float 3;
#A 0 -0.380956 0.752384 0.819052 0.619048 1.00953 0.761905 0.609524
0.657143 0.419048 0.809528;
#X coords 0 1 10 0 150 105 1 0 0;
#X restore 412 136 graph;
#X obj 412 284 tgl 20 0 empty empty empty 17 7 0 10 -262130 -1 -1 0
1;
#X obj 536 304 tgl 20 0 empty empty empty 17 7 0 10 -257985 -1 -1 0
1;
#X obj 412 309 metro 2000;
#X obj 412 448 s NOTE;
#X obj 412 343 riff 600 3791;
#X msg 479 255 symbol riff10;
#N canvas 0 23 450 278 (subpatch) 0;
#X array riff12 10 float 3;
#A 0 0.4 0.133332 -0.180956 0.142857 -0.257145 0.295238 0.104762 -0.161906
-0.361908 0.466668;
#X coords 0 1 10 0 150 105 1 0 0;
#X restore 593 140 graph;
#X obj 593 288 tgl 20 0 empty empty empty 17 7 0 10 -262130 -1 -1 0
1;
#X obj 717 308 tgl 20 0 empty empty empty 17 7 0 10 -257985 -1 -1 0
1;
#X obj 593 313 metro 2000;
#X obj 593 452 s NOTE;
#X msg 660 259 symbol riff10;
#X msg 469 276 symbol riff13;
#X msg 650 280 symbol riff12;
#X obj 56 390 radio_bongbong;
#X obj 593 347 riff 600 4200;
#X obj 222 238 riff 200 3791;
#N canvas 0 23 450 278 (subpatch) 0;
#X array riff22 10 float 3;
#A 0 -0.161907 0.104762 -0.257147 0.304763 0.190476 -0.285718 0.390476
-0.371432 0.323809 -0.238097;
#X coords 0 1 10 0 150 105 1 0 0;
#X restore 389 502 graph;
#X obj 389 650 tgl 20 0 empty empty empty 17 7 0 10 -262130 -1 -1 0
1;
#X obj 513 670 tgl 20 0 empty empty empty 17 7 0 10 -257985 -1 -1 0
1;
#X obj 389 675 metro 2000;
#X obj 389 814 s NOTE;
#X msg 456 621 symbol riff10;
#X obj 389 709 riff 600 4203;
#X msg 446 642 symbol riff22;
#X connect 3 0 5 0;
#X connect 4 0 14 3;
#X connect 5 0 14 0;
#X connect 4 0 13 3;
#X connect 5 0 13 0;
#X connect 6 0 8 0;
#X connect 7 0 11 3;
#X connect 8 0 11 0;
#X connect 11 0 10 0;
#X connect 12 0 14 1;
#X connect 13 0 11 1;
#X connect 14 0 9 0;
#X connect 7 0 31 3;
#X connect 8 0 31 0;
#X connect 11 0 13 1;
#X connect 12 0 31 1;
#X connect 13 0 9 0;
#X connect 15 0 17 0;
#X connect 16 0 19 3;
#X connect 17 0 19 0;
#X connect 19 0 18 0;
#X connect 20 0 19 1;
#X connect 22 0 24 0;
#X connect 23 0 30 3;
#X connect 24 0 30 0;
#X connect 26 0 30 1;
#X connect 27 0 19 1;
#X connect 28 0 30 1;
#X connect 30 0 25 0;
#X connect 31 0 10 0;
#X connect 33 0 35 0;
#X connect 34 0 38 3;
#X connect 35 0 38 0;
#X connect 37 0 38 1;
#X connect 38 0 36 0;
#X connect 39 0 38 1;

View file

@ -21,7 +21,7 @@
//============<identities>============
//
#define MY_GROUP_ID (4000)
#define MY_ID (MY_GROUP_ID + 100)
#define MY_ID (MY_GROUP_ID + 200)
#define MY_SIGN ("ROLLER")
//
//============</identities>============