Advertisement
prjbrook

Sender3.ino Boardwalk ESPNow Network sensor

Dec 2nd, 2022
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.73 KB | None | 0 0
  1.  
  2.  
  3. //New direction. Add littleFS to HTU_0SantosSensor7.ino .Now SpudSensor Mon Aug 29 14:44:53 NZST 2022
  4. /*
  5. C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor0\SpudSensor0.ino works ok by sending
  6. good temp and humid data from HDU21 to C:\Users\Dell\Documents\Arduino\WorkingAugust22\SantosMaster6\SantosMaster6.ino using Wemos 1
  7. ..to WemosII
  8. Going to adorn the HTU_0SantosSensor7.ino so that it's LittleFS intelligent. Bit by bit. Also cleaning up old code and comments to get SpudSensor as strong and sparse as possible. Also want to try out #include files for some parts of the code that get in the way,
  9. The include file,tryme works. Now try to fill it useful LittleFS stuff
  10. Tidied up some of below. Put LittleFs into next version.
  11. Working: C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor3\SpudSensor3.ino
  12. Now using C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor5\SpudSensor5.ino
  13. Going to add sampling string stuff to fill up struc to espnow send
  14. C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor5\SpudSensor5.ino Works ok
  15. ..above works with boss: C:\Users\Dell\Documents\Arduino\WorkingAugust22\SantosMaster6\SantosMaster6.ino
  16. Sun Sep 4 11:47:30 NZST 2022. Now starting on ..C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor6\SpudSensor6.ino
  17. Now going to add lots of small routines to take readings and send them to boss and littlefs logfile. Mon Sep 5 14:46:38 NZST 2022. File is :
  18. C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor7\SpudSensor7.ino and talks to ...master6
  19. Spud..7 worked out with a lot of cleanup and several new buffer[] helpers
  20. Nw going to work on: C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor8\SpudSensor8.ino
  21. same Boss: C:\Users\Dell\Documents\Arduino\WorkingAugust22\SantosMaster6\SantosMaster6.ino
  22. Going to add more routines to get sensor readings into litleFs and boss side.
  23. Some buffer problems in previous version. Have gone away? Now going to tidy up code and try to use ic files
  24. ...to help witj comprehension. Haven't done much with boss side yet.
  25. Now onto C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor91\SpudSensor91.ino..still tidying up look of terminal output to hel with debugging. Fri Sep 9 12:02:24 NZST 2022. Also, take out stringplay. Now onto C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor91\SpudSensor91.ino at Sat Sep 10 13:16:48 NZST 2022. Getting strange millis times for packets coming and going. Will get exact millis time by writing it down during callbacks.
  26. Next, just tidying up. C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor93\SpudSensor93.ino Mon Sep 12 12:16:30 NZST 2022 putting in fixFullBuffer() to reset buffer when no room to fit more readings. Other little tidy ups. Going well.
  27. Decided to time main loop so I can see when sensing of temperature etc starts and stops as well as espNow stuff
  28. Thu Sep 15 12:29:29 NZST 2022, C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor94\SpudSensor94.ino
  29. C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor94C\SpudSensor94C.ino. Playing with files.
  30. The current date is: Mon 26/09/2022. C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor94D\SpudSensor94D.ino ... finished ...
  31. ..playing with files. Now, next version, want to get a sendFile() going that sends logfile from sensorWemos to Listener. Now on C:\Users\Dell\Documents\Arduino\WorkingAugust22\SpudSensor94E\SpudSensor94E.ino
  32. Now Wed Sep 28 11:49:02 NZDT 2022. Nearly thru with sending file from sender-Wemos. JUst tidy up with SpudSensor94F.ino
  33. Now Thu Sep 29 11:10:15 NZDT 2022. Using SpudSensor94G.ino. Nearly sending file from WemosI (sensor) to WemosII(listener)
  34.  
  35. Sat Oct 1 13:01:35 NZDT 2022 New sketch folder for C:\Users\Dell\Documents\Arduino\WorkingOctober22\SpudSensor94G\SpudSensor94G.ino .
  36. Current file going to pastebin is: C:\Users\Dell\Documents\Arduino\WorkingOctober22\SpudSensor94H\SpudSensor94H.ino
  37. SpudSensor94H.ino now Sender01.ino Sat Oct 15 12:36:04 NZDT 2022
  38. C:\Users\Dell\Documents\Arduino\WorkingOctober22\Sender02\Sender02.ino Mon Oct 17 12:22:35 NZDT 2022
  39. Still making code tidy. Take away stop watch stuff and get read sequence right.
  40. Next, send logfile. Now in Sender03.ino. Going to send main log file.
  41. */
  42. //50
  43.  
  44. #include <FS.h>
  45. #include <LittleFS.h>
  46. #include <time.h>
  47. #include <ESP8266WiFi.h>
  48. #include <espnow.h>
  49. #include <Wire.h>
  50. #include "SparkFunHTU21D.h"
  51.  
  52.  
  53. #include "helperCode.h"
  54. #include "globals.h"
  55.  
  56.  
  57.  
  58. HTU21D myHumidity;
  59.  
  60.  
  61. // Callback when data is sent
  62. void OnDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
  63. if (sendStatus == 0){
  64. Serial.print("\nPacket sent.");
  65. Serial.printf(" At time %lu",millis());
  66. }
  67. else{
  68. Serial.printf("\nDelivery fail\n");
  69. }
  70. }
  71.  
  72. // Callback when data is received
  73. void OnDataRecv(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
  74. memcpy(&incomingReadings, incomingData, sizeof(incomingReadings));
  75.  
  76. incomingTemp = incomingReadings.temp;
  77. incomingHum = incomingReadings.hum;
  78. incomingMillisA= incomingReadings.millisA;
  79. incomingOrders=incomingReadings.ord;
  80. for(int i =0;i<10;i++) incomingStac[i]=incomingReadings.stac[i];
  81. incomingStackPtr=incomingReadings.stacPtr;
  82. incomingBufferPtr=incomingReadings.bufPtr;
  83. for(int i =0;i<10;i++) incomingBigBuffer[i]=incomingReadings.bigBuf[i];
  84.  
  85. RxFlag =1; //tell loop() we've dgot a packet
  86. globLen = len; //Need this to output length in loop()
  87. onDataRecvMillis =millis();
  88. }
  89.  
  90.  
  91. void printIncomingReadings(){
  92. // Display Readings in Serial Monitor.
  93. Serial.println("\n\n---------------INCOMING READINGS from Master ----------------------");
  94. Serial.print("Temperature: ");
  95. Serial.print(incomingTemp);
  96. Serial.println(" ºC");
  97. Serial.print("Humidity: ");
  98. Serial.print(incomingHum);
  99. Serial.println(" %");
  100. Serial.print("Millies: ");
  101. Serial.println(incomingMillisA);
  102. Serial.print("IncomingOrders: ");
  103. Serial.println(incomingOrders);
  104. Serial.print("IncomingStackPtr: ");
  105. Serial.println(incomingStackPtr);
  106.  
  107. for(int i =0;i<10;i++) {Serial.print( incomingStac[i]);}
  108. Serial.println(" <--incomingStac[]");
  109. for(int i =0;i<200;i++) Serial.print( incomingBigBuffer[i]);
  110. Serial.println(" <--incomingBigBuffer[]");
  111. }
  112.  
  113. void setup() {
  114. // Init Serial Monitor
  115. Serial.begin(115200);
  116. myHumidity.begin();
  117. pinMode(LED_BUILTIN, OUTPUT);
  118.  
  119. // Set device as a Wi-Fi Station
  120. WiFi.mode(WIFI_STA);
  121. WiFi.disconnect();
  122.  
  123. // Init ESP-NOW
  124. if (esp_now_init() != 0) {
  125. Serial.println("Error initializing ESP-NOW");
  126. return;
  127. }
  128.  
  129. // Set ESP-NOW Role
  130. esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
  131.  
  132. // Once ESPNow is successfully Init, we will register for Send CB to
  133. // get the status of Trasnmitted packet
  134. esp_now_register_send_cb(OnDataSent);
  135.  
  136. // Register peer
  137. esp_now_add_peer(broadcastAddress, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
  138.  
  139. // Register for a callback function that will be called when data is received
  140. esp_now_register_recv_cb(OnDataRecv);
  141.  
  142. interval=8000; //slow it down a bit
  143. startLittleFs();
  144. delay(500);
  145.  
  146. //LittleFS.remove("/log0.txt"); //delete didn't work
  147. clearBuffer();
  148.  
  149. // sendFile("/testFile0.txt"); //initial practice file sensor-->listener
  150. delay(500);
  151. // sendFile2("/testFile0.txt"); //initial practice file sensor-->listener
  152. // sendFile2("/log0.txt"); //test this important routine
  153.  
  154. }
  155.  
  156. //--------------------------------------------------------------
  157. void loop() {
  158. unsigned long currentMillis = millis();
  159.  
  160. if (currentMillis - previousMillis >= interval) {
  161. previousMillis = currentMillis; //NB programmable delay.
  162.  
  163. doLED2();
  164. getReadings2(); //read the sensor and note start time
  165.  
  166. //Set values to send to Master Wemos2
  167. sensorReadings.temp = temperature; //these values go into struc
  168. sensorReadings.hum = humidity;
  169. sensorReadings.millisA=millis();
  170. sensorReadings.ord = 52; //'52' = just a normal sensor packet
  171.  
  172. saveReadings(); //readings to strings,files save?,fill bigBuf[]?
  173.  
  174. esp_now_send(broadcastAddress, (uint8_t *) &sensorReadings, sizeof(sensorReadings));
  175.  
  176. if (RxFlag==1) {
  177. Serial.printf("\nGot a packet, length is: %d Time is:%lu and onDataRecvMillis is:%lu and Loop Counter is:%lu\n\n",globLen,millis(),onDataRecvMillis,loopCounter);
  178. RxFlag=0;
  179. loopCounter=0;
  180. }
  181. numReadings++; //Serial.printf("\nNumber of readings is %lu: ",numReadings);
  182. }
  183. //loopCounter++;
  184. }
  185.  
  186.  
  187.  
  188. void getReadings2(){
  189. temperature = myHumidity.readTemperature(); //both temperature and humidity are global floats
  190. humidity= myHumidity.readHumidity();
  191. Serial.printf("\n\n=======================New Reading of Sensors ==%d========3=====\n",numReadings);
  192. Serial.print("Time:");
  193. Serial.print(millis());
  194. Serial.print(" Temperature:");
  195. Serial.print(temperature, 1);
  196. Serial.print("C");
  197. Serial.print(" Humidity:");
  198. Serial.print(humidity, 1);
  199. Serial.print("%");
  200. }
  201.  
  202.  
  203. void startLittleFs() {
  204. // LittleFS.format(); //take this out after first go!
  205. LittleFS.setTimeCallback(myTimeCallback); //best I can do without getting date from internet
  206.  
  207. Serial.println("Mount LittleFS using *LittleFS.begin()*");
  208. if (!LittleFS.begin()) {
  209. Serial.println("LittleFS mount failed");
  210. return;
  211. }
  212. Serial.println("Mount done^*^");
  213. Serial.println("Now going to use *listDir* from root");
  214. listDir("/");
  215. }
  216.  
  217.  
  218. void saveReadings() { //Take readings and make them strings and put into File? Also put strings into buffer[] and, if it's big enough save to file and send to espNow boss.
  219.  
  220. unsigned long myTime;
  221. myTime=millis();
  222. int irdTemp= (uint16_t)temperature;
  223. int irdHum= (uint16_t)humidity; //both from HTU21D read
  224.  
  225. sprintf(text, "%d\t%d\t%lu]", irdTemp,irdHum,myTime);
  226. Serial.printf("\nText buf is: %s In hex: ", text);
  227.  
  228. for(int i = 0;i<20;i++) {
  229. Serial.printf("%x,",text[i]);
  230. }
  231. Serial.println();
  232. displayBufferStatsBanner();
  233. showFirst10();
  234. showFirstZero();
  235. showBufferLength();
  236. showNumOfBracs();
  237. showTextLen();
  238. showNumReadings();
  239. showLast10() ;
  240. displayBufferStatsBanner();
  241. addTextToBuffer2();
  242. //appendToLogFile2("/log0.txt"); //if log file fills up too fast, delete this line when testing
  243.  
  244. }
  245.  
  246. void showBufferHex() { //print the intermediate buffer to see all the sensor strings
  247. for(int i = 0;i<20;i++) {
  248. Serial.printf("buffer[%u] is : %x ",i,buffer[i]);
  249. }
  250. Serial.printf("\nLength of buffer[] is %d ", strlen(buffer));
  251. }
  252. void clearBuffer() {
  253. for (int i=0;i<200;i++) buffer[i]=0; //clear intermediate buffer
  254. }
  255. void showFirst10() { //show start of buffer[]
  256. for(int i = 0;i<15;i++) Serial.printf("%x,",buffer[i]); //Actually 15 not 10
  257. }
  258. void showFirstZero() { //check out zeros in buffer.
  259. int gotAZero = 0;
  260. int numZeros = 0;
  261. int firstZeroPos = 0;
  262. for(int i = 0;i<200;i++) {
  263. if(buffer[i]==0) {
  264. if(gotAZero==0) { //must be first zero
  265. gotAZero=1;
  266. firstZeroPos=i;
  267. }
  268. numZeros++;
  269. }
  270. }
  271. Serial.printf(" fz%d and %dnz",firstZeroPos,numZeros);
  272. }
  273.  
  274. void showBufferLength() { //Buffer is 200 bytes long but what's len of string inside?
  275. int strLen=0;
  276. strLen = strlen(buffer); //char,char ..char then \0. Maybe whole buffer
  277. Serial.printf(" BL%d ",strLen);
  278. }
  279.  
  280. void showNumOfBracs() { //each reading produces one ']'
  281. int numBrac=0;
  282. for(int i = 0;i<200;i++) {
  283. if(buffer[i]==']') {numBrac++; }
  284. }
  285. Serial.printf(" [%d] ",numBrac);
  286. }
  287.  
  288. //showTestLen() below: little buffer called text[] takes readings as strings then to buffer along with the other readings
  289. void showTextLen() {
  290. int textLen=0;
  291. textLen= strlen(text);
  292. Serial.printf(" TL%dTL ",textLen);
  293. }
  294. void showLast10() { //show end part of buffer[]
  295. for(int i = 185;i<200;i++) Serial.printf("%x.",buffer[i]); //Last 15 actually
  296. }
  297.  
  298. void displayBufferStatsBanner() { //Otherwise hard to find
  299. Serial.printf("\n------------------Stats for buffer[] --------------------\n");
  300. }
  301.  
  302. void appendToLogFile2(const char * path) { //When buffer gets full save it in log file
  303. //use like this : appendToLogFile2("/log0.txt"); //buffer variable is global. Maybe change later.
  304. appendFile(path,buffer); //filled buffer goes onto end of log file. Works!
  305. listDir(path);
  306. //appendFile("/hello.txt", "----Wor\nld5!\n");
  307. }
  308. //In addTextToBuffer() below : In each reading produces two ints, temperature and humidityas well as millis and a ']' tacked on the end. Also \n. It will be a string because it's put there by sprint() (which tacks on the zero?). This little buffer, ie text[] gets appended to bigger buffer[] if there's space for it.(See: textCanFitQ() )
  309.  
  310. void addTextToBuffer() {
  311. if(strlen((buffer) + strlen(text)) < 180) {
  312. strcat(buffer,text); //buffer = buffer + text
  313. Serial.printf("\nAdded to buffer.");
  314. }
  315. else{
  316. Serial.printf("Buffer overflow333333333333333333333. Readings num is:%d\n------------------Stats",numReadings);
  317. }
  318. }
  319.  
  320. void showNumReadings() { //how many times have we asked HTU21Dfor temperature etc?
  321. Serial.printf(" R%dR ",numReadings);
  322. }
  323.  
  324. void addTextToBuffer2() {
  325. int slenB=strlen(buffer);
  326. int slenT = strlen(text);
  327. int slenTotal = slenB+slenT;
  328.  
  329. if((slenB + slenT) < 195) {
  330. strcat(buffer,text); //buffer = buffer + text
  331. Serial.printf("\nAdded to buffer.");
  332. }
  333. else{
  334. Serial.printf("\n***Buffer overflow333***.\n Readings num is:%d ",numReadings);
  335.  
  336. //*********better send buffer to log file here before buffer gets zerod and started again with next reading.
  337. //*** appendToLogFile2("/log0.txt"); //try this here
  338.  
  339. fixFullBuffer();
  340. }
  341. Serial.printf("Lengths B%d, T%d, Sum%d", slenB, slenT, slenTotal);
  342. }
  343. void fixFullBuffer() { //come here when buffer overflows if next reading inserted
  344. clearBuffer(); //200 zeros. Hope old buffer saved.
  345. strcat(buffer,text); //reading now goes in front.
  346. Serial.printf("@@@Buffer cleared.\n");
  347. showBufferHex();
  348. }
  349. void getStopWatch(int num) { //insedrt to see time. Used with showStopWatchSettings()
  350. unsigned long millisNow=millis();
  351. stopWatchSettings[num] = millisNow;
  352. }
  353. void showStopWatchSettings() { //Find timing and duration of parts of code.
  354. stopWatchSettings[6]=millis(); //So can print time now in loop below.
  355. for(int i=0;i<6;i++) {
  356. Serial.printf("sssssss%dsssss%lu;%lu , ",i,stopWatchSettings[i],stopWatchSettings[i+1]-stopWatchSettings[i]); //Time then distance to next time
  357. }
  358.  
  359. }
  360. void doFile0() { //don't need this now
  361. createTestFile("/testFile0.txt",1234);
  362. listDir("/testFile0.txt");
  363. showFileHeadAndTail("/testFile0.txt") ;
  364. sendFile("/testFile0.txt");
  365.  
  366. }
  367.  
  368. void showFileHead2(const char * path){ //show first 10 bytes of file in parameter in serial output
  369. File f=LittleFS.open(path,"r");
  370. if(!f){
  371. Serial.print("Cannot open file in showFileHead2.");
  372. return;
  373. }
  374. if (f.size() <10){
  375. Serial.printf("File too small.\n");
  376. }
  377. else {
  378. Serial.printf("\nFirst ten bytes of %s are: ",path);
  379. for (int i=0;i<10;i++) {
  380. Serial.printf("[%d]%c ",i,f.read());
  381. }
  382. f.close();
  383. }
  384. }
  385. void showFileTail2(const char * path) {
  386. File f=LittleFS.open(path,"r");
  387. if(!f){
  388. Serial.print("Cannot open file in showFileHead2.");
  389. return;
  390. }
  391. if (f.size() <10){
  392. Serial.printf("File too small for showFileTail2 .\n");
  393. }
  394. else {
  395. Serial.printf("\nLast ten bytes of %s are: ",path);
  396.  
  397. // for (int i = 1; i < 10 + 1; i++) {
  398. for (int i = 1; i < 15 + 1; i++) {
  399. f.seek(i,SeekEnd);
  400. Serial.printf("[%d]%c ",f.position(),f.read());
  401. }
  402. f.close();
  403. }
  404. }
  405. void createTestFile(const char * path, uint16_t sizeOfFile) { //create file of given size. For testing
  406. // Use like this : createTestFile("/testFile0.txt",1234);
  407. uint16_t fileCount=0;
  408. char ascChar=48; //insert into file f
  409. //File * g;
  410. File f=LittleFS.open(path,"w");
  411. //g= &f;
  412. if(!f){
  413. Serial.print("Cannot open file in showFileHead2.");
  414. return;
  415. } //create new file. Empty at start.
  416. if((sizeOfFile<2)|(sizeOfFile>65535)){
  417. Serial.printf("Size of file outside limits");
  418. return;
  419. }
  420. else {
  421. while(fileCount++ < sizeOfFile) {
  422. f.write(ascChar++);
  423. if(ascChar>122) { ascChar=48;} //if we get to 'z' go back 20 '1'
  424. }
  425. }
  426. }
  427. void showFileHeadAndTail(const char * path) { //peek at both ends of file
  428. //Use like this: showFileHeadAndTail("/testFile0.txt") ;
  429. showFileHead2(path);
  430. showFileTail2(path);
  431. }
  432.  
  433. void sendFile(const char * path) { //send a log file from sensor to listener using espNow
  434. //Use like this: sendFile("/testFile0.txt");
  435.  
  436. uint16_t numOfChunks=0;
  437. uint16_t extras=0;
  438. int i,j;
  439.  
  440. File f=LittleFS.open(path,"r");
  441. if(!f){
  442. Serial.print("Cannot open file in sendFile fn.");
  443. return;
  444. }
  445. if (f.size() > 65535){
  446. Serial.printf("\nFile too big for sendFile fn .\n");
  447. }
  448. numOfChunks= f.size()/200; //integer division, check
  449. extras= f.size()%200;
  450. for( j=0;j<numOfChunks;j++) {
  451. for(i=0;i<200;i++) {
  452. sensorReadings.bigBuf[i]=f.read(); //fill struct buffer with file chars ready to send
  453. }
  454. espNowSendChunk(j,51); //send chunk j with orders that it's just a normal"51" type.
  455. delay(5); //give Listener time to put data away to file
  456. }
  457. Serial.printf("\nAll done. Number of chunks: %d extras: %d i=%d j=%d size=%d", numOfChunks,extras,i,j,f.size());
  458. doExtras(f,extras); //worked ok. g.fullName() is new for me Suggested by Arduino compiler
  459. }
  460. void doExtras( File g,uint16_t numOfExtras) { //sendFile getting too big. Trying tricky parameter passing.
  461. //Use like this: doExtras(f,extras); f has to be an open file. extras is nuber of leftover bytes in last file buffer send. See sendFile()
  462. Serial.printf("\nAdding in extras. File name is %s and extras are: %d",g.fullName(),numOfExtras);
  463. for(int i=0;i<numOfExtras;i++) {
  464. sensorReadings.bigBuf[i]=g.read(); //fill struct buffer with file chars ready to send
  465. }
  466. sensorReadings.stac[2] = numOfExtras; //Nedw marker to show last struc send, fragmented.
  467. sensorReadings.ord = 59; //59 is code for extras sent, that's all done
  468. sensorReadings.bigBuf[numOfExtras]=0; //tack 0 onto end of extras to help with strine handling
  469. esp_now_send(broadcastAddress, (uint8_t *) &sensorReadings, sizeof(sensorReadings)); //send usual structure
  470. Serial.printf("\nTried to send %d extras with orders %d ", numOfExtras,59);
  471. }
  472.  
  473. void espNowSendChunk(uint16_t chunkNum,uint8_t ordersByte) {
  474. //use like this: espNowSendChunk(6,51); ie send the 6th chuck from file opened to WemosII with orders=51,ie a normal chunkNum
  475. sensorReadings.stac[0] = chunkNum/256; //high bytr
  476. sensorReadings.stac[1] = chunkNum%256; //low byte
  477. sensorReadings.ord = 51; //51 is orders code for normal chuck from Wemos 1
  478. sensorReadings.millisA=millis();
  479. esp_now_send(broadcastAddress, (uint8_t *) &sensorReadings, sizeof(sensorReadings)); //send usual structure
  480. //delay(100); //give time to receiver to take espNow msg
  481. delay(200);
  482. Serial.printf("\nTried to send chunk %d with orders %d ", chunkNum,ordersByte);
  483. }
  484. void sendFile2(const char * path) { //send a log file from sensor to listener using espNow
  485. //Use like this: sendFile("/testFile0.txt");
  486. //better than sendFile() as it tacks 0 on end of buf to make it a string
  487.  
  488. uint16_t numOfChunks=0;
  489. uint16_t extras=0;
  490. int i,j;
  491.  
  492. File f=LittleFS.open(path,"r");
  493. if(!f){
  494. Serial.print("Cannot open file in sendFile fn.");
  495. return;
  496. }
  497. if (f.size() > 65535){
  498. Serial.printf("\nFile too big for sendFile fn .\n");
  499. }
  500. numOfChunks= f.size()/200; //integer division, check
  501. extras= f.size()%200;
  502. for( j=0;j<numOfChunks;j++) {
  503. for(i=0;i<199;i++) {
  504. sensorReadings.bigBuf[i]=f.read(); //fill struct buffer with file chars ready to send
  505. sensorReadings.bigBuf[199] = 0;
  506. }
  507. espNowSendChunk(j,51); //send chunk j with orders that it's just a normal"51" type.
  508. delay(5); //give Listener time to put data away to file
  509. }
  510. Serial.printf("\nAll done. Number of chunks: %d extras: %d i=%d j=%d size=%d", numOfChunks,extras,i,j,f.size());
  511. doExtras(f,extras); //worked ok. g.fullName() is new for me Suggested by Arduino compiler
  512. f.close();
  513. }
  514.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement