├── LICENSE
├── README.md
├── WhyzaGC-3.5-ESP32-release.ino
├── WhyzaGC-3.5-ESP8266-release.ino
├── WhyzaGC_4_4_ESP32-release.ino
├── WhyzaGC_4_7_ESP32_release.ino
├── WhyzaGC_4_8_ESP32_release.ino
└── WhyzaGC_4_9_ESP32_release.ino
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WhyzaGC
2 | Feather Huzzah ESP8266/ESP32 v2 + Featherwing 128x64 OLED Arduino addon to MightyOhm Geiger Counter C++
3 | ---
4 | permlink: /README.md/
5 | title: README
6 | ---
7 |
8 | This project is about building your own DIY wireless Adafruit Arduino Feather HUZZAH ESP8266 or ESP32 v2 microprocessor with the Adafruit Featherwing 128x64 OLED display add-on to interface with the self-assembled DIY MightyOhm Geiger Counter Kit. Additionally, I have included an optional random number generator based on the random timing of the radiation counts for education and fun.
9 |
10 | 
11 |
12 | ## Introduction:
13 |
14 | I am always on the lookout for unique and interesting kits to build, which led me to discover the MightyOhm Geiger kit.
15 |
16 | While there are a couple of other Geiger kits around, the fact that the MightyOhm included a commonly used detector tube (for relative data comparisons), had serial data output, and sported steampunk looks, had me sold.
17 |
18 | Initially, I started with the ESP8266 and then 'upgraded' to the ESP32 to take advantage of the dual-core as I ran into limitations multitasking on the ESP8266, as discussed below.
19 |
20 | As such, I would recommend the Feather Huzzah ESP32 v2 over the original ESP8266 version due to both the NeoPixel RGB LED and dual-core functionality. That said, if you already have a Feather Huzzah ESP8266, it will work just fine. However, I have released version 4 software only for the ESP32, which brings MQTT support.
21 |
22 | I have packed as many software features as I can think of in an attempt to learn as much as possible about ESP software development.
23 |
24 | I also discovered Radmon.org, which seemed like a worthwhile project to contribute data to. It has a very simple and easy registration process and runs on solar power! Your data will be retained by radmon.org for 2 years. If you donate your data will be retained for 5 years.
25 |
26 | While waiting for delivery, I checked a number of forums looking for ideas on how to interface with the counter for both the Raspberry Pi and Arduino platforms. I found a dated project using the Feather Huzzah ESP8266 and the MightyOhm for inspiration, but it was not going to compile on the current libraries. So, I decided to do my own Arduino project from scratch as I also wanted to increase my Arduino coding skills. I also found some good ideas for interfacing with the Raspberry Pi, which I also cover.
27 |
28 | It was also a good opportunity to learn a lot more about radiation, quantum physics, and our environment.
29 |
30 | The MightyOhm measures background radiation levels, which Wikipedia defines as 'Background radiation originates from a variety of sources, both natural and artificial. These include both cosmic radiation and environmental radioactivity from naturally occurring radioactive materials (such as radon and radium), as well as man-made medical X-rays, fallout from nuclear weapons testing, and nuclear accidents.'
31 |
32 | The most interesting explanation of the whole radioactive process and how you can use it in practical ways, I found, is discussed in this next link from a fascinating long-standing project now well and truly obsolete in this era of microcontrollers and modern CPU design. Created by John Walker, who started Autodesk/AutoCAD with others, it is a great read.
33 |
34 | https://www.fourmilab.ch/hotbits/how3.html
35 |
36 | I bought a number of items to test out the meter's functionality, which are discussed below.
37 |
38 | It is recommended to read all of this document before commencing the project.
39 |
40 | ## Features:
41 |
42 | Adafruit Feather Huzzah ESP8266 and ESP32 v2 support, OLED display, Li-Po battery.
43 |
44 | Button inputs select between 3 OLED data display modes showing different formats, including bar meter strength graphs, detailed data, plus an auto-scaling histogram (photos below).
45 |
46 | Radmon.org data upload every 60 seconds.
47 |
48 | Web server diagnostics available via HTTP over port 80 (data, radmon.org upload status, debug, uptime).
49 |
50 | Blue LED/Neopixel blue heartbeat, Red LED CPS (for Counts per Second <= 5).
51 |
52 | Monitoring of MightyOhm's serial data for disconnections.
53 |
54 | MightyOhm serial data over HTTP and Telnet.
55 |
56 | mDNS multicast name registration.
57 |
58 | Neopixel radmon status feedback.
59 |
60 | OTA Software upgrades via WiFi.
61 |
62 | NTP client for OLED and web server time display.
63 |
64 | Unix syslog status messages to your syslog server.
65 |
66 | Random number generator at a rate of 1 character per two pulses detected.
67 |
68 | Customisable Bootup animation logo.
69 |
70 | MQTT support on version 4 for the ESP32 platform.
71 |
72 | ## Parts list:
73 |
74 | MightyOhm Geiger Counter DIY kit with GM tube and clear case (https://www.adafruit.com/products/483 and https://mightyohm.com/blog/products/geiger-counter/).
75 |
76 | Either Feather Huzzah ESP8266 (https://www.adafruit.com/product/2821) or Feather Huzzah ESP32 v2 (https://www.adafruit.com/product/5400), ( https://core-electronics.com.au/adafruit-esp32-feather-v2-8mb-flash-2-mb-psram-stemma-qt.html )
77 |
78 | Featherwing 128x64 OLED (https://www.adafruit.com/product/4650), ( https://core-electronics.com.au/adafruit-featherwing-oled-128x64-oled-add-on-for-feather-stemma-qt-qwiic.html ).
79 |
80 | Stacking Headers for Feather - 12-pin and 16-pin female headers (https://www.adafruit.com/product/2830).
81 |
82 | Li-Po battery to replace the original AAA batteries (https://www.adafruit.com/product/258).
83 |
84 | Micro USB (Huzzah ESP8266) or USB C (Huzzah ESP32 v2) cable to connect your PC to the Feather.
85 |
86 | Double-sided tape.
87 |
88 | Female breadboard jumper wires to connect to Raspberry Pi if desired.
89 |
90 | A test source of radiation, discussed in Testing below.
91 |
92 | ## Assembly
93 |
94 | While assembling your MightyOhm, if you are yet to do so, do not install the AAA battery holder as this is where the Feather Huzzah is to be placed. If you have assembled your kit, you will need to remove the battery holder.
95 |
96 | Start by soldering the stacking headers to the Huzzah and the supplied headers on the Featherwing OLED, as documented in Adafruit's online guide for your hardware. Familiarize yourself with all the documentation.
97 |
98 | We first need to connect the MightyOhm Geiger to the Huzzah. You can use a breadboard to test your setup if desired, or you can simply dive in and solder the required 3 wires between the Huzzah and the MightyOhm. Optionally, you can include a 4th wire if you would like to enable and play with the random number generator. I used a small gauge wire so I was able to feed the 4 wires through the circuit board hole under the battery cover.
99 |
100 | With the rear of the MightyOhm accessible, the first wire to connect is the MightyOhm Geiger serial TX pin, which is found on J7 pin 4 on the MightyOhm. This is connected to GPIO 13 on the Huzzah ESP8266 and GPIO 27 on the Huzzah ESP32 via the bottom of the board. This is pin 6 on the top, from left to right (from the front!) on both Huzzah versions and is the blue wire shown below.
101 |
102 | If you want to include the random number functionality, wire from the MightyOhm center pulse pin on J6 to GPIO 12. GPIO 12 is pin 5 next to pin 6 noted above on both Huzzah versions and is the yellow wire in the image below.
103 |
104 | Finally, connect the Huzzah's 3.3v and GND pins to the MightyOhm's battery connections, which are the red and black wires below. Refer to the images at the end of this document for both the Feather Huzzah's and the MightyOhm Geiger's header pinouts.
105 |
106 | 
107 |
108 | You will notice in the above photo I have soldered a single stacking header pin on the bottom of the Huzzah on the VBUS/USB pin. I have soldered it at a right angle so I can connect Raspberry Pi's 5v supply to power the Feather Huzzah (and charge the Li-Po battery) via a jumper cable from the Pi's header.
109 |
110 | Note that when the Huzzah is mounted in the MightyOhm, access is lost to the onboard USB serial connection, so you will need to upload the software mentioned below before final assembly. Once the software is loaded, you can use the OTA WiFi update feature if required when the Huzzah is mounted in its final position in the MightyOhm Geiger for upgrades.
111 |
112 | After verifying the software below and the hardware is functional by connecting the Li-Po battery and checking operation, only then apply the double-sided tape and secure the Feather Huzzah to the MightyOhm AAA battery space and the Li-Po battery to the rear piece of the plastic case on the MightyOhm.
113 |
114 | ## Software:
115 |
116 | Tested on Arduino IDE 1.8.19/2.1.0 and ESP8266 Boards 3.0.2/ESP32 2.0.5 with Arduino on Ubuntu Linux desktop 20.04/22.04 using both the Feather Huzzah ESP8266 and Feather Huzzah ESP32 v2.
117 |
118 | To support the Feather Huzzah, add the following to File -> Preferences -> Additional Board Manager URL if not done already. This example has 2 entries for both the ESP8266 and ESP32 boards:
119 |
120 | http://arduino.esp8266.com/stable/package_esp8266com_index.json,https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
121 |
122 | Then, in the Board Manager, install esp8266 or esp32 to reflect the hardware you have.
123 |
124 | Finally, select the appropriate board via Tools -> Board -> ESP32 Arduino -> Adafruit Feather ESP32 V2 or Tools -> Board -> ESP8266 Boards -> Adafruit Feather Huzzah ESP8266.
125 |
126 | Connect to your PC via the USB cable, and you should see the Huzzah fire up and show serial output @ 115200 baud in the Arduino IDE. After selecting the correct baud, you should be able to load and run sample code under File -> Examples to verify hardware functionality, such as Basics -> Blink or WiFi -> WiFiScan.
127 |
128 | WhyzaGC Arduino C++ software for ESP8266 and ESP32 versions is available at:
129 |
130 | Latest version available at https://github.com/Whyzanet/WhyzaGC
131 |
132 | Download the correct C++ ino sketch file for your hardware, either ESP8266 or ESP32.
133 |
134 | Note: The Feather Huzzah ESP8266 will require the Frequency set to 160MHz to accommodate high values of CPS/CPM.
135 |
136 | At the top of the sketch are the variables that will need changing for your specific environment. Register with radmon.org first so you have your required credentials.
137 |
138 | The following libraries are available via the Arduino Library Manager and will need to be installed. I have listed the version that I tested under.
139 |
140 | ESPSoftwareSerial(8.03)
141 |
142 | ArduinoHttpClient(0.4.0)
143 |
144 | Tlog(1.03) , Logs output to serial, telnet and http simultaneously
145 |
146 | NTPClient(3.2.1)
147 |
148 | Adafruit_GFX(1.11.5)
149 |
150 | Adafruit_SH110X(2.1.8)
151 |
152 | Adafruit Feather OLED(2.0.2)
153 |
154 | Adafruit NeoPixel (ESP32)(1.11.0)
155 |
156 | Uptime Library(1.0.0)
157 |
158 | CircularBuffer(1.3.3)
159 |
160 | PubSubClient(2.8)
161 |
162 | The following libraries will need to be downloaded to your library directory:
163 |
164 | movingAvg(2.3.1): [https://github.com/JChristensen/movingAvg]
165 |
166 | Syslog(2.0.0): [https://github.com/arcao/Syslog]
167 |
168 | ESP8266mDNS(1.2) (for ESP8266): [https://github.com/LaborEtArs/ESP8266mDNS]
169 |
170 | The code in essence reads the serial data from the MightyOhm using SoftwareSerial via a GPIO pin, displays this data in various ways on the OLED, and uses movingAvg to average the CPM (Count per Minute) over 1 minute and subsequently upload the result to radmon.org via an HTTP client GET.
171 |
172 | The histogram graph utilizes the circularBuffer library, which made the graphing relatively easy.
173 |
174 | There are a number of networking functions which should be self-explanatory (mDNS, Web server, NTP client, serial to telnet/HTTP, Unix syslog, OTA upgrades).
175 |
176 | The random number generator uses the pulse signal from the MightyOhm to generate an interrupt which will read the current value from a looping counter (basically a roulette wheel) that loops and counts from 0 to 15, which is then output as a hex value to serial/telnet/HTTP (Tlog). Collating and analyzing this random output is discussed below.
177 |
178 | The code is broken up into individual functions, so if you want to see how one of the functions work, it should be straightforward.
179 |
180 | Below is a list of the main functions:
181 |
182 | wifion: Activate WiFi, setup Web server, OTA upgrades, and NTP client.
183 |
184 | wifioff: Deactivate WiFi and radmon updates.
185 |
186 | serialmon: Monitor the MightyOhm serial connection for disconnects longer than 15 seconds.
187 |
188 | grab: Read the MightyOhm serial data via SoftwareSerial GPIO RX pin.
189 |
190 | process: Check for valid MightyOhm EOL serial data, flash the heartbeat LED, extract the required data for variables, averages, and histogram display.
191 |
192 | grabgraphdata: Grab current data for histogram circularBuffer.
193 |
194 | averagedata: Average CPM data for radmon update.
195 |
196 | mqttpub: Publish MQTT sensor data together with WiFi online and last radmon upload status. There are separate timers for each if you want to customize. Image below of HomeAssistant intergration via mosquitto MQTT broker. Pinned to CPU0 and only on the ESP32.
197 |
198 | radmon: Once per minute, flash the NeoPixel purple (ESP32), perform the HTTP Get with radmon.org, and flash the NeoPixel (ESP32) red or green based on the result. Radmon will reject uploads if attempting to update before 30 seconds has expired since the last update. "Too soon" will appear in the log output ( TLOG and syslog ) if this occurs.
199 |
200 | handleRootPath: Configure the web diagnostics & upgrades with the HTTP server.
201 |
202 | logstats: Send Unix syslog messages each hour.
203 |
204 | buttons: Check for button input.
205 |
206 | smallData: Display all data available in a small size font.
207 |
208 | mediumData: Display all Geiger Counter Data in a medium-size font.
209 |
210 | largeData: Display minimal CPS/CPM data in a large font size.
211 |
212 | histogramData: Display histogram graph.
213 |
214 | runntp: Update NTP time at the update interval.
215 |
216 | randomise: Looping counter from 0 to 15 roulette wheel used for random number generation. Pinned to CPU0 on ESP32.
217 |
218 | grabrandomnum: The function called by the interrupt to grab a number from the roulette wheel loop. Triggered by the pulse pin on the MightyOhm.
219 |
220 | echorandom: Display the random number on a new line via Tlog to serial/telnet/HTTP.
221 |
222 | setup: Initialization, animate bitmap logo, start WiFi if enabled.
223 |
224 | bootupbitmap: Function holding bitmap data. Replace with your own logo via http://javl.github.io/image2cpp/ Ensure your logo is 128 x 64 pixels.
225 |
226 | Upload the sketch and check for any missing libraries you may need.
227 |
228 | Once running, input is via the 3 OLED Featherwing buttons. Button A and Button C will cycle up and down, respectively, through the 3 available data display modes. Button B selects the histogram display mode. See photos below of different display outputs.
229 |
230 | Buttons B & C together will toggle WiFi disable and enable, which I found easy to select as the buttons are small enough and so close together. WiFi disable will also disable radmon.org updates and will require a reset to enable radmon.org uploads if radmon startup behavior is enabled. As such, if you toggle WiFi off and back on, you will have WiFi connectivity, but radmon updates are disabled until the next reset... useful for testing, as per below.
231 |
232 | The USB serial port is set to 115200 baud and will display the MightyOhm Geiger serial output (when not mounted in the kit and accessible).
233 |
234 | HTTP diagnostic data is available on port 80 via URL http://whyzagc-esp.local
235 |
236 | Monitor easily via the following Linux terminal command:
237 |
238 | watch -n 10 curl -s whyzagc-esp.local
239 |
240 | To monitor the MightyOhm serial data remotely over HTTP, use http://whyzagc-esp.local:81, and serial data is also available in your favorite telnet program: telnet whyzagc-esp.local
241 |
242 | Blue Heartbeat LED/Neopixel is triggered by an EOL from the Geiger serial output. It should flash 1 per second as a result. If Geiger serial EOL data is not detected, the heartbeat will stop.
243 |
244 | Feather Huzzah ESP32 v2 Neopixel will flash purple every 60 secs when starting the radmon.org update and then will flash green when having completed a successful update, or red when detecting an unsuccessful update.
245 |
246 | OTA upgrading of compiled sketch .bin via WiFi using the following URL: http://whyzagc-esp.local/upload using WebServer.h.
247 |
248 | To locate the correct binary for upload, within the Arduino IDE interface, select Sketch -> Export Compiled Binary, which will drop the compiled binary into the same location as the ino sketch file.
249 |
250 | Alternately, version 4 software has ArduinoOTA.h WiFi upgrade support and as such should show up as a network port in the Arduino IDE via mDNS where you can simply use Sketch --> Upload. Select Tools --> Ports -> WHyzaGC at a.b.c.d
251 |
252 | WiFi (OTA) software updates, HTTP server diagnostics, and MightyOhm serial port redirection over telnet/HTTP all work around limitations with the USB serial port being inaccessible when the Huzzah is mounted in the MightyOhm's original AA battery location, preventing USB serial port access to upgrades, diagnostics, and MightyOhm raw data.
253 |
254 | MQTT support on version 4 publishes the following subscriptions to the MQTT-configured broker which HomeAssistant digests
255 |
256 | WhyzaGC/CPM: Average of count per minute published every 60 secs.
257 |
258 | WhyzaGC/sieverts: Measured sieverts/hr from the MightyOhm output.
259 |
260 | WhyzaGC/status: Publishes a status of online when WiFi is brought up successfully.
261 |
262 | WhyzaGC/radmon_status: Publishes a status when radmon.org accessibility goes down or up."
263 |
264 | Check out the Home Assistant Image below.
265 |
266 | ## Testing
267 |
268 | There are several items you can collect to test radiation detection.
269 |
270 | The SBM20 tube detects limited-range high-energy beta particle radiation (also known as electrons) and penetrating long-range gamma electromagnetic radiation (also known as photons), but not short-range alpha particle radiation, which is stopped by the tube's metallic outer composition. This is fine, as you don’t want to be playing with hazardous alpha radiation sources anyway (e.g., a smoke alarm’s Americium-241).
271 |
272 | Vaseline glass contains uranium, making it a useful item for background level radiation testing and is easily available on eBay. The radiation from Vaseline glass is mostly stopped by aluminum, which fits the definition of being mostly beta radiation. Additionally, Vaseline glass/uranium glows a fluorescent bright green under UV light.
273 |
274 | Other testing options include volcanic rock, granite benchtops, some types of Fiesta tableware (due to the colored glazing used), or chunks of uranium from http://unitednuclear.com/.
275 |
276 | I bought a ‘nano-technology, ionizing anti EMF’ therapeutic volcanic pendant necklace, and while it gives a relatively weak count among my samples, only 90+ CPM, that works out to about 4.5 mSieverts/year, which is 4.5 times the annual normal background exposure of 1 mSieverts/year here in Australia (which is still very small). Its glossy product documentation has a long list of varied health benefits, including fighting cancer cells and protection from harmful 5G technology, if worn on the skin due to its ‘scalar energy’.
277 |
278 | I also picked up from United Nuclear a small specimen bottle of uranium ore chunks, a Cloud Chamber Source (a bigger chunk of uranium ore), a geiger counter test card, and a Fiestaware glazed plate. The respective measured CPM readings in order of radioactivity are below:
279 |
280 | Background radiation: 18 CPM
281 |
282 | Therapeutic volcanic pendant: 90 CPM
283 |
284 | Vaseline glass: 173 CPM
285 |
286 | United Nuclear small specimen bottle of uranium ore chunks: 1700 CPM
287 |
288 | United Nuclear geiger counter test card: 2700 CPM
289 |
290 | No name tableware red/orange glazed plate: 6500 CPM
291 |
292 | Fiesta tableware red/orange glazed plate: 9200 CPM
293 |
294 | United Nuclear Cloud Chamber Source (chunk of uranium): 27300 CPM
295 |
296 | The maximum tested using a combination of samples listed above and both the SBM-20 tube and an SBT-11 pancake detector: 1366 CPS or 82000 CPM.
297 |
298 | An airplane flight would also be an interesting test environment due to increased cosmic radiation levels at altitude. Latitude also affects background cosmic radiation, with higher levels the closer you are to the poles. An interesting calculator is available at https://jag.cami.jccbi.gov/
299 |
300 | Fiesta tableware plate, therapeutic volcanic pendant, United Nuclear uranium ore chunks, and geiger counter test card.
301 |
302 | 
303 |
304 | ## ESP8266/ESP32/OLED specific settings
305 |
306 | As noted above, the Feather Huzzah ESP8266 will require the CPU Frequency set to 160MHz to accommodate high values of CPS/CPM.
307 |
308 | Other than the expected differences in libraries for the ESP8266 & ESP32, respectively (ESP8266WiFi.h/WiFi.h, ESP8266WebServer.h/WebServer.h, and ESP8266mDNS/ESPmDNS), the 2nd LED differences (Blue LED vs. Neopixel RGB LED), and pinout changes, the Feather Huzzah ESP32 CPU is also dual-core.
309 |
310 | As such, in the ESP32 code, I have set both the radmon.org update, MQTT publish and randomise functions to utilize CPU0 rather than CPU1, which all other code runs on by default.
311 |
312 | This solves two issues on the ESP8266 platform due to its single CPU and my less than proficient programming skills. Firstly, while performing the TCP connection setup and GET request for the radmon.org update, the (single) CPU is unavailable for other tasks. Since the typical TCP setup, data exchange, and teardown takes at least 1.5+ seconds in my environment (and up to N secs!), resulting in the ESP8266 missing N lines of serial data from the MightyOhm, one per second. This is not a significant issue as the code is reading the MightyOhm CPM (Counts per Minute) value, which is itself averaged and uploading the resulting Arduino-calculated 1-minute rolling average. So the impact of missing a couple of average values is negligible overall. It explains why the code is measuring the upload time and showing it in the web diagnostics. I did try schedulers and yield() without success on the ESP8266....
313 |
314 | Secondly, because the roulette wheel function generating the random data is time-critical, any sharing of CPU will corrupt the random data. My initial tests confirm this.
315 |
316 | This is not a problem on the ESP32, where the radmon.org function (and the functions it calls) and the randomise function are both pinned to CPU0 while the default CPU1 is free to carry out other tasks. When not uploading to radmon, CPU0 is available to the randomise function.
317 |
318 | The other hardware consideration is that I can confirm that OLED screen burn-in does occur with the default contrast and use over 1000 hours, as noted on the Adafruit site, resulting in a contrast deviation as the datasheet explains it. As such, I have now set the contrast to a minimum to preserve the screen. This setting is near the top of the ino file if you desire to change it.
319 |
320 | ## Random number generator.
321 |
322 | It is worth mentioning this link again if you are interested in how random numbers can be generated from natural events such as radioactive decay:
323 |
324 | https://www.fourmilab.ch/hotbits/how3.html
325 |
326 | I was also inspired by this project, which has some good ideas and explained the tools for use in validating random numbers:
327 |
328 | https://github.com/gbonacini/nuclear_random_number_generator
329 |
330 | As mentioned, I added a simple random number generator, which seems to work well on the ESP32 platform. The random number generator uses the pulse signal from the MightyOhm to generate a hardware interrupt, which will read the current value from a looping counter (basically a roulette wheel) that counts from 0 to 15. This value is then output as a hex value to serial/telnet/HTTP (Tlog).
331 |
332 | It is disabled by default. You can enable it via 'true' or 'false' at the top section of the ino file:
333 |
334 | bool randomon = true; // enable random number generator
335 |
336 | Generating data using only background radiation levels takes some time as you only generate one random character per 2 pulses. I did testing with high counts utilizing some of the radiation samples I have and found that the output data was far from random. I believe this is due to the SMB20 saturating and the associated dead zone when the tube is rendered insensitive.
337 |
338 | The random numbers are available via the serial, HTTP, or telnet connection. A character is output on a new line for each pulse when enabled.
339 |
340 | To analyze the data, I installed 'ent' (written by John Walker mentioned above from http://www.fourmilab.ch/) via:
341 |
342 | apt-get install ent
343 |
344 | I then downloaded the test directory from the nuclear_random_number_generator project above, 'cd' to this test directory where you can run:
345 |
346 | ./test_random_numbers.sh
347 |
348 | to format and test the included rnd_nums.txt data.
349 |
350 | Running
351 |
352 | ent -c rnd_nums.bin
353 |
354 | will analyze the data per character, while
355 |
356 | ent -b -c rnd_nums.bin
357 |
358 | will analyze the data per bit.
359 |
360 | The manpage for 'ent' describes the tests performed.
361 |
362 | I collected random data from the Huzzah via the telnet data output using the following command on my Linux desktop:
363 |
364 | nc whyzagc-esp.local 23 | tee -a rnd_nums.txt
365 |
366 | and waited about 5 days until I had about 15M raw data, which gave me around 50K of binary random data once filtered.
367 |
368 | I had to change line 6 in test_random_numbers.sh from:
369 |
370 | cat rnd_nums.txt | grep -v '^CPM' | tr -d '\r\n' | head -204800 > rnd_nums.clean.txt
371 |
372 | to the rather convoluted:
373 |
374 | cat rnd_nums.txt | cut -c -2 | grep --binary-files=text -v 'CP|Te|19|C|BP|PS|GP' | cut -c -1 | grep --binary-files=text '0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f' | grep --binary-files=text -v -e '^$' | tr -d '\r\n' > rnd_nums.clean.txt
375 |
376 | to ensure the filtered data collected via the nc command was free of the MightyOhm serial output and nc's output messages. You may need to modify this if your environment is different from mine (e.g., the '19' in the search field is a match from the first two characters of 192.168.0.100, the address nc is connecting to). This address is obviously not meant to be in the final random data.
377 |
378 | Once you have run test_random_numbers.sh over your new data in rnd_nums.txt, you can analyze your data as per above with the ent command or visually with:
379 |
380 | ./scatter.py rnd_nums.bin
381 |
382 | I have attached my ESP32 scatter graph below.
383 |
384 | I have initially found that the ESP8266 platform does not pass the Chi-square distribution test under ent and is visibly not random when inspecting the scatter graph. This is no doubt due to the limitations of only one CPU where you cannot dedicate the time-critical randomize counter to a spare CPU. On the ESP32 hardware, I have pinned the randomize function to the previously underutilized CPU0. CPU0 was only performing the once per minute Radmon & MQTT uploads, so other than these uploads, which will pause the randomize function, it is available for dedicated use.
385 |
386 | So with the ESP32, a $40 micro marvel of today's world, it is reassuring to be able to actually confirm that the universe really IS composed of such truly random events or occurrences of quantum tunneling, which can't be explained by our classical understanding of physics, despite even Einstein believing, 'God does not play dice with the universe.' If Einstein could ask today's AI, 'What are the implications and observations that can be made when understanding the universe is based on random quantum events?' he would see a list of several fascinating observations and interpretations that we can now make since Einstein's ( 1879 - 1955 ) time. Look it up yourself for a good read.
387 |
388 | ## Additional Connections:
389 |
390 | I am connecting the VBUS/USB pin on the Huzzah to a Raspberry Pi 5V pin via the Pi GPIO header, as well as a ground connection between the two boards. The current is usually around 110 mA, though it will peak at around 300 mA when charging the Li-Po battery, which probably means any 5V supply will suffice.
391 |
392 | I am also connecting the Geiger serial TX pin (J7 pin 4) to the Raspberry Pi 4's additional serial Rx pins on UART 4 and 5 (the default serial port is already in use) by setting dtoverlay=uart4 and dtoverlay=uart5 in the Pi's /boot/config.txt file and then connecting the Geiger serial TX pin to both pins 33 and 21. These additional serial ports are found under /dev/ttyAMA1 and /dev/ttyAMA2 under Raspberry Pi OS Bullseye. On one port, I have configured a bash script to perform radmon.org updates for use if I don't want to upload from the Feather Huzzah for whatever reason. The other port is used by a Perl script that displays graphs using rrdtool. See the RPI 4 pinout below for the additional serial ports or use "raspi-gpio funcs" from the command line to show GPIO additional functions.
393 |
394 | See this link for the Perl script. Read the whole page before starting:
395 |
396 | https://mightyohm.com/forum/viewtopic.php?t=3504
397 |
398 | Finally, I also have the MightyOhm pulse pin (J6 pin 2) connected to pin 35 on the Pi 4, so that a bash script can look for a rising edge on GPIO 19. I use this to log occurrences of high CPS (Counts per Second) for when I need to reconfirm the randomness of the universe.
399 |
400 | ## Images
401 |
402 | MightyOhm with connections to Raspberry Pi pictured below. Red is 5V supply, Orange is serial TX, Yellow is pulse, and brown is GND
403 |
404 | 
405 |
406 | Default bootup/histogram display mode
407 |
408 | 
409 |
410 | All data display mode while capturing a MightyOhm LED trigger
411 |
412 | 
413 |
414 | Geiger data display mode
415 |
416 | 
417 |
418 | CPS & CPM large display mode
419 |
420 | 
421 |
422 | HTTP diagnostics:
423 |
424 | 
425 |
426 | Telnet output of MightyOhm serial data with random number output enabled
427 |
428 | 
429 |
430 | Vaseline Glass sourced from Ebay. In addition to ( and independently of ) emitting radiation, Vaseline glass/uranium also glows a fluorescent bright green under UV light.
431 |
432 | 
433 |
434 | Scatter Graph visually showing the true randomness of the detected events on the ESP32 platform ( around 100K bytes of collected random data ). A non random result would show patterns of waves and/or clumps and empty spaces, which are not evident in the true random image below.
435 |
436 | 
437 |
438 | HomeAssistant intergration via Mosquito MQTT broker.
439 |
440 | 
441 |
442 | Raspberry Pi Graphs using rrdtool
443 |
444 | 
445 |
446 | Radmon Site
447 |
448 | 
449 |
450 | Radmon data
451 |
452 | 
453 |
454 | Adafruit Feather Huzzah ESP8266 pinout
455 |
456 | 
457 |
458 | Adafruit Feather Huzzah ESP32 v2 pinout. ADC2 is used by WiFi if enabled and not available for IO. Pin 32 is also not available as it is used by the B button on the OLED screen feather.
459 |
460 | 
461 |
462 | MightyOhm Geiger schematic showing header pinout configurations.
463 |
464 | 
465 |
466 | Raspberry Pi 4 pinout showing additional serial ports. Use "raspi-gpio funcs" to list alternative GPIO functions such as serial ports. This image is missing TXD3 which "raspi-gpio funcs" shows is GPIO 4 or pin 7. Further info here. https://raspberrypi.stackexchange.com/questions/104464/where-are-the-uarts-on-the-raspberry-pi-4
467 |
468 | 
469 |
470 | ## Latest Version
471 |
472 | The latest version of this document and project is available via:
473 |
474 | https://github.com/Whyzanet/WhyzaGC
475 |
--------------------------------------------------------------------------------
/WhyzaGC-3.5-ESP32-release.ino:
--------------------------------------------------------------------------------
1 | // Latest version available https://github.com/Whyzanet/WhyzaGC
2 | const char* release = "WhyzaGC v3.5";
3 | const char* releasedate = "Released 3/11/2022";
4 |
5 | bool WIFIEnable = true; // set startup wifi client behaviour
6 | const char* ssid = "CHANGEME"; // Set wifi SSID
7 | const char* password = "CHANGEME"; // Set wifi password
8 | int TZ = +10; // Set local timezone offset from UTC CHANGEME
9 | bool radmonen = true; // Set startup radmon.org behaviour. Will enable WIFI if reqd
10 | const char* radmonuser = "CHANGEME"; // Set radmon.org username
11 | const char* radmonpass = "CHANGEME"; // Set radmon.org password
12 | const char* ntpServer = "pool.ntp.org"; // Set ntp server
13 | const char* hostname = "WhyzaGC-ESP";
14 | uint8_t mode = 5; // Startup default OLED display mode - Graph Display ( Buttons A&B )
15 | #include
16 | SoftwareSerial mySerial(27, 33); // Gieger serial port directly connected on RX, TX ( no TX connection needed as only receiving data )
17 | #include
18 | #define SYSLOG_SERVER "192.168.0.138" // Set syslog server
19 | #define SYSLOG_PORT 514 // Syslog port
20 | #define DEVICE_HOSTNAME "WhyzaGC-ESP" // Set syslog hostname
21 | const char* APP_NAME = "my-function";
22 | #include
23 | WebServer server(80); // Set web server port
24 | int contrast = 0; // reduce OLED contrast to preserve OLED lifespan
25 | bool randomon = false; // enable random number generator
26 | int pulsepin = 12;
27 |
28 | #include // The T-Logging library.
29 | // Run a telnet service on the default port (23) which shows what is
30 | // sent to Serial if you telnet to it.
31 | //
32 | #include
33 | TelnetSerialStream telnetSerialStream = TelnetSerialStream();
34 | // Likewise let http://:81/ show the log in a webbrowser.
35 | //
36 | #include
37 | WebSerialStream webSerialStream = WebSerialStream(81);
38 |
39 | #include
40 | #include
41 | const char* serverIndex = "";
42 | #include
43 | #include // we need to do some averaging
44 | #include
45 | #include
46 | #include
47 | #include
48 | #include
49 | #include
50 | #include
51 | #include
52 | #include "uptime_formatter.h"
53 | #include // Histogram data
54 | #define buttonA 15
55 | #define buttonB 32
56 | #define buttonC 14
57 | Adafruit_FeatherOLED_SH110X oled = Adafruit_FeatherOLED_SH110X();
58 | WiFiUDP ntpUDP;
59 | NTPClient timeClient(ntpUDP, ntpServer);
60 | WiFiUDP udpClient;
61 | movingAvg cpmminavg(60);// keep a 1 minute moving average of CPM data to upload
62 | movingAvg cpmhouravg(3600);
63 | movingAvg timerdelayavg(60);
64 | movingAvg timerdelaydayavg(1440);
65 | CircularBuffer xpoints; // mode 5 histogram graph data
66 | unsigned long uploadcpm = 0;
67 | unsigned long cpmhour = 0;
68 | unsigned long uploaddelay = 0; // measure the radmon upload time.
69 | unsigned long lastupdate = 0;
70 | unsigned long avgdelay = 0;
71 | unsigned long logdelay = 0;
72 | unsigned long timeravg = 0;
73 | unsigned long timerdayavg = 0;
74 | unsigned long buttontimer = 0;
75 | String Release = release;
76 | String ReleaseDate = releasedate;
77 | String Hostname = hostname;
78 | int statusCode = 0;
79 | uint8_t oldmode;
80 | bool geigerConnected = false;
81 | String geigerconnected;
82 | unsigned long geigerTimeout = 0;
83 | bool gotButton = false;
84 | String geigerSerial;
85 | unsigned char geigerdata;
86 | String webdata;
87 | int barz = 0;
88 | int cps = 0;
89 | int cpm = 0;
90 | int xsize = 0;
91 | int xplot = 0;
92 | float sieverts = 0;
93 | float svyear = 0;
94 | float battery = oled.getBatteryVoltage();
95 | char buffer[255];
96 | unsigned long timer = 0;
97 | unsigned long timertotal = 0;
98 | float scale = 0; // Setup histogram variables
99 | int recenthi = 0;
100 | int previoushi = 0;
101 | bool scale0 = false;
102 | bool scale1 = false;
103 | bool scale2 = false;
104 | bool scale3 = false;
105 | bool scale4 = false;
106 | bool scale5 = false;
107 | bool scale6 = false;
108 | bool scale7 = false;
109 | bool scale8 = false;
110 | bool scale9 = false;
111 | bool scale10 = false;
112 | bool scale11 = false;
113 | bool scale12 = false;
114 | bool scale13 = false;
115 | bool scale14 = false;
116 | unsigned long grabgraphdatadelay = 0;
117 | int randomresult = -1;
118 | int gotrandomresult = 0x00;
119 | #define PIN 0 //NeoPixel
120 | #define NUMPIXELS 1
121 | Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
122 | #define COMMON_ANODE
123 | TaskHandle_t Task1;
124 | TaskHandle_t Task2;
125 | bool newrandom = false;
126 |
127 | const unsigned char bootupbitmap [] PROGMEM = {
128 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
129 | 0x00, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130 | 0x00, 0x00, 0x07, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131 | 0x00, 0x00, 0x1f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132 | 0x00, 0x00, 0x7f, 0x00, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 | 0x00, 0x01, 0xf8, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 | 0x00, 0x07, 0xe0, 0x7f, 0xe0, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
135 | 0x00, 0x0f, 0x83, 0xff, 0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136 | 0x00, 0x1e, 0x1f, 0xff, 0xff, 0x87, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137 | 0x00, 0x3c, 0x1f, 0xff, 0xff, 0xc1, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138 | 0x00, 0x78, 0x1f, 0xff, 0xff, 0x80, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
139 | 0x00, 0xf0, 0x0f, 0xff, 0xff, 0x80, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140 | 0x01, 0xe0, 0x0f, 0xff, 0xff, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
141 | 0x01, 0xc0, 0x07, 0xff, 0xff, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
142 | 0x03, 0x80, 0x03, 0xff, 0xfe, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
143 | 0x07, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
144 | 0x07, 0x00, 0x01, 0xff, 0xfc, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
145 | 0x0e, 0x00, 0x01, 0xff, 0xf8, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
146 | 0x0e, 0x00, 0x00, 0xff, 0xf8, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
147 | 0x1c, 0x00, 0x00, 0xff, 0xf0, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
148 | 0x1c, 0x00, 0x00, 0x7f, 0xf0, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
149 | 0x18, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150 | 0x38, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
151 | 0x38, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
152 | 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
153 | 0x30, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe0, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
154 | 0x30, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x00, 0xe0, 0xe7, 0x3b, 0x80, 0x00, 0x00, 0x01, 0xfc, 0x7f,
155 | 0x30, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x00, 0xe0, 0xe7, 0xbb, 0x80, 0x00, 0x00, 0x03, 0xfc, 0xff,
156 | 0x70, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0xe0, 0xff, 0xbb, 0xfb, 0x9f, 0xfb, 0xf7, 0x81, 0xe0,
157 | 0x70, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x60, 0x7f, 0xfb, 0xfb, 0xbc, 0x78, 0xf7, 0x81, 0xe0,
158 | 0x73, 0xff, 0xfe, 0x7f, 0xe7, 0xff, 0xfc, 0x60, 0x7f, 0xf3, 0xbb, 0xf8, 0xf8, 0x3f, 0x3d, 0xc0,
159 | 0x73, 0xff, 0xff, 0x7f, 0xe7, 0xff, 0xfc, 0xe0, 0x7d, 0xf3, 0xb9, 0xf9, 0xf7, 0xff, 0x9d, 0xe0,
160 | 0x33, 0xff, 0xff, 0x3f, 0xe7, 0xff, 0xfc, 0xe0, 0x7d, 0xf3, 0xb9, 0xfb, 0xe7, 0xff, 0x9d, 0xe0,
161 | 0x31, 0xff, 0xff, 0x1f, 0xcf, 0xff, 0xfc, 0xe0, 0x3d, 0xf3, 0xb8, 0xf3, 0xc7, 0xfb, 0xfc, 0xff,
162 | 0x31, 0xff, 0xff, 0x8f, 0x8f, 0xff, 0xfc, 0xe0, 0x3c, 0xe3, 0xb8, 0xf3, 0xff, 0xf9, 0xfc, 0x7f,
163 | 0x39, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xfc, 0xe0, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00,
164 | 0x39, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xf8, 0xc0, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00,
165 | 0x39, 0xff, 0xff, 0xc0, 0x1f, 0xff, 0xf9, 0xc0, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00,
166 | 0x18, 0xff, 0xff, 0x80, 0x1f, 0xff, 0xf9, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167 | 0x1c, 0xff, 0xff, 0x80, 0x0f, 0xff, 0xf1, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
168 | 0x1c, 0x7f, 0xff, 0x00, 0x07, 0xff, 0xf3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
169 | 0x0e, 0x7f, 0xfe, 0x00, 0x07, 0xff, 0xe3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
170 | 0x0e, 0x3f, 0xfe, 0x00, 0x03, 0xff, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
171 | 0x07, 0x3f, 0xfc, 0x00, 0x03, 0xff, 0xc7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
172 | 0x07, 0x1f, 0xfc, 0x00, 0x01, 0xff, 0x8e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
173 | 0x03, 0x8f, 0xf8, 0x00, 0x01, 0xff, 0x9e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
174 | 0x01, 0xc7, 0xf8, 0x00, 0x00, 0xff, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
175 | 0x01, 0xe3, 0xf0, 0x00, 0x00, 0x7e, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
176 | 0x00, 0xf1, 0xe0, 0x00, 0x00, 0x7c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
177 | 0x00, 0x78, 0xe0, 0x00, 0x00, 0x30, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
178 | 0x00, 0x3c, 0x00, 0x00, 0x00, 0x21, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
179 | 0x00, 0x1e, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180 | 0x00, 0x0f, 0x80, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
181 | 0x00, 0x07, 0xe0, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
182 | 0x00, 0x01, 0xf8, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
183 | 0x00, 0x00, 0x7f, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
184 | 0x00, 0x00, 0x1f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
185 | 0x00, 0x00, 0x07, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
186 | 0x00, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
187 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
188 | };
189 |
190 | //***Functions***
191 |
192 |
193 | void IRAM_ATTR grabrandomnum () {
194 | detachInterrupt(pulsepin);
195 | newrandom = true;
196 | gotrandomresult = ( randomresult );
197 | // while (digitalRead(pulsepin) == 0);
198 | attachInterrupt(digitalPinToInterrupt(pulsepin), grabrandomnum, RISING);
199 | }
200 |
201 | void randomise (void * ptParameters ) {
202 | for (;;) {
203 | if (randomresult == 0xF) {
204 | randomresult = 0;
205 | delay (1);
206 | }
207 | else {
208 | randomresult = (randomresult + 1);
209 | delay (1);
210 | }
211 | }
212 | }
213 |
214 | void echorandom () {
215 | if (newrandom == true) {
216 | Log.println("");
217 | Log.printf("%01x", gotrandomresult);
218 | newrandom = false;
219 | }
220 | }
221 |
222 | void stopWiFiAndSleep() { // Stop sleep
223 | WiFi.disconnect(true);
224 | WiFi.mode(WIFI_OFF);
225 | delay(3);
226 | }
227 | void wifion () { //enable WiFi
228 | sprintf(buffer, "%s\n%s\n", release, releasedate);
229 | Serial.println("");
230 | Serial.println(" ________ __ ____ __");
231 | Serial.println("| | | || |_ .--.--.|_ / .-----. .-----.-----.| |_");
232 | Serial.println("| | | || || | | / /_ | - | _ | | -__|| _|");
233 | Serial.println("|________||__|_||__ ||____||___|_||_||__|__|_____||____|");
234 | Serial.println(" |__| ");
235 |
236 | oled.clearDisplay();
237 | oled.setCursor(0, 0);
238 | oled.setTextSize(1);
239 | Serial.print(buffer);
240 | oled.print(buffer);
241 | battery = oled.getBatteryVoltage();
242 | oled.setBattery(battery);
243 | oled.renderBattery();
244 | oled.println("\n");
245 | APP_NAME = "wifion: ";
246 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
247 | if (WIFIEnable == true) {
248 | sprintf(buffer, "Connecting to\n%s\n", ssid);
249 | oled.print(buffer);
250 | Serial.print(buffer);
251 | oled.display();
252 | WiFi.setHostname(Hostname.c_str());
253 | WiFi.begin(ssid, password);
254 | int retries = 0;
255 | while ((WiFi.status() != WL_CONNECTED) && (retries < 15)) {
256 | retries++;
257 | delay(500);
258 | Serial.print(".");
259 | oled.print(".");
260 | oled.display();
261 | }
262 | }
263 | sprintf(buffer, "\nWiFi status\nIPv4: %s\n", WiFi.localIP().toString().c_str());
264 | Serial.print(buffer);
265 | oled.print(buffer);
266 | oled.display();
267 | delay(1500);
268 | if (WiFi.waitForConnectResult() == WL_CONNECTED) {
269 | MDNS.begin(hostname);
270 | timeClient.begin(); // Start NTP client
271 | timeClient.setTimeOffset(3600 * TZ);
272 | timeClient.setUpdateInterval(43200000);
273 | server.on("/", handleRootPath); // Setup web servers for root and upload
274 | server.on("/upload", HTTP_GET, []() {
275 | server.sendHeader("Connection", "close");
276 | server.send(200, "text/html", serverIndex);
277 | });
278 | server.on("/update", HTTP_POST, []() {
279 | server.sendHeader("Connection", "close");
280 | server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
281 | ESP.restart();
282 | }, []() {
283 | HTTPUpload& upload = server.upload();
284 | if (upload.status == UPLOAD_FILE_START) {
285 | Serial.printf("Update: %s\n", upload.filename.c_str());
286 | if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
287 | Update.printError(Serial);
288 | }
289 | } else if (upload.status == UPLOAD_FILE_WRITE) {
290 | /* flashing firmware to ESP*/
291 | if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
292 | Update.printError(Serial);
293 | }
294 | } else if (upload.status == UPLOAD_FILE_END) {
295 | if (Update.end(true)) { //true to set the size to the current progress
296 | Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
297 | } else {
298 | Update.printError(Serial);
299 | }
300 | Serial.setDebugOutput(false);
301 | }
302 | });
303 | server.begin();
304 | MDNS.addService("http", "tcp", 80);
305 |
306 | Serial.printf("Stats available:\n");
307 | Serial.printf("http://%s.local\n", hostname);
308 | Serial.printf("Software upload:\n");
309 | Serial.printf("http://%s.local/upload\n", hostname);
310 | } else {
311 | Serial.println("WiFi Failed");
312 | }
313 | syslog.log(LOG_INFO, buffer);
314 | oled.clearDisplay();
315 | oled.setCursor(0, 0);
316 | runntp();
317 | }
318 | void wifioff () { // disable WiFi
319 | APP_NAME = "wifioff: ";
320 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
321 | syslog.log(LOG_INFO, "WiFi Disconnect and Powersave");
322 | syslog.log(LOG_INFO, "Will require a reboot to enable radmon.org if enabled");
323 | radmonen = false;
324 | delay(3);
325 | stopWiFiAndSleep();
326 | oled.clearDisplay();
327 | oled.setTextSize(1);
328 | battery = oled.getBatteryVoltage();
329 | oled.setBattery(battery);
330 | oled.renderBattery();
331 | oled.setCursor(0, 0);
332 | sprintf(buffer, "%s\n%s\n\nDisconecting from\n%s\n\nWiFi disconnected\n%s\n\nWifi powersaving on", release, releasedate, ssid, WiFi.localIP().toString().c_str());
333 | oled.print(buffer);
334 | Serial.print(buffer);
335 | oled.display();
336 | delay(2500);
337 | oled.clearDisplay();
338 | }
339 | void grabgraphdata () { // grab histogram graph data for mode 5 display
340 | if (millis() > (grabgraphdatadelay + 1000)) {
341 | // if (cpm >= 1) {
342 | xpoints.push(cpm);
343 | xsize = xpoints.size();
344 | xplot = xpoints.last();
345 |
346 | // for (decltype(xpoints)::index_t i = 0; i < xpoints.size(); i++) {
347 | // Serial.print(xpoints[i]);
348 | // }
349 | // Serial.println(" ");
350 | grabgraphdatadelay = millis();
351 | }
352 | }
353 | void logstats () { // remote syslog status
354 | if (millis() > (logdelay + 3600000)) {
355 | APP_NAME = "logstats:";
356 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
357 | syslog.logf(LOG_INFO, "Latest 1 min average CPM: %d", uploadcpm);
358 | syslog.logf(LOG_INFO, "Latest 1 hour average CPM: %d", cpmhour);
359 | syslog.logf(LOG_INFO, "Latest HTTP response: %d", statusCode);
360 | logdelay = millis();
361 | }
362 | }
363 |
364 | void averagedata () { // calculate CPM data average for radmon upload
365 | if (millis() > (avgdelay + 550)) {
366 | uploadcpm = cpmminavg.reading(cpm);
367 | cpmhour = cpmhouravg.reading(cpm);
368 | avgdelay = millis();
369 | }
370 | }
371 | void radmon (void * ptParameters ) { // perfrom the HTTP Get for radmon.org every minute
372 | for (;;) {
373 | if (radmonen == 1 && (geigerConnected == true)) {
374 | if (WIFIEnable == 0 || WiFi.status() != WL_CONNECTED) {
375 | statusCode = 0;
376 | }
377 | if (WIFIEnable == 1 && (millis() > (uploaddelay + 59999 - timertotal))) {
378 | if (WiFi.status() != WL_CONNECTED) {
379 | wifion();
380 | }
381 | else {
382 | pixels.clear();
383 | pixels.setPixelColor(0, pixels.Color(255, 0, 255)); // flash neopixel purple when starting http client upload
384 | pixels.show();
385 | delay(80);
386 | pixels.clear();
387 | pixels.show();
388 | delay(80);
389 | pixels.setPixelColor(0, pixels.Color(255, 0, 255));
390 | pixels.show();
391 | delay(80);
392 | pixels.clear();
393 | pixels.show();
394 | String ptr = "/radmon.php?function=submit";
395 | ptr += "&user=";
396 | ptr += radmonuser;
397 | ptr += "&password=";
398 | ptr += radmonpass;
399 | ptr += "&value=";
400 | ptr += uploadcpm;
401 | ptr += "&unit=CPM";
402 | timer = (millis());
403 | WiFiClient wifi;
404 | HttpClient client = HttpClient(wifi, "www.radmon.org", 80);
405 | client.get(ptr);
406 | statusCode = client.responseStatusCode();
407 | lastupdate = uploadcpm;
408 | uploaddelay = millis();
409 | timertotal = (millis() - timer);
410 | // Serial.println(timertotal);
411 | timeravg = timerdelayavg.reading(timertotal);
412 | timerdayavg = timerdelaydayavg.reading(timertotal);
413 | if (statusCode == 200) {
414 | flashgreen (); // successful update
415 | }
416 | else {
417 | flashalertred (); // unsuccessful update
418 | }
419 | // Serial.println(timeravg);
420 | // Serial.print("radmon uploaded using core ");
421 | // Serial.println(xPortGetCoreID());
422 | }
423 | }
424 | }
425 | delay(1000);
426 | }
427 | }
428 | void runntp () { // run the NTP client
429 | timeClient.update();
430 | //Serial.println(timeClient.getFormattedTime());
431 | //Serial.println(timeClient.getFormattedDate());
432 | }
433 | void flashgreen () { // radmon update successful
434 | pixels.clear();
435 | pixels.setPixelColor(0, pixels.Color(0, 255, 0));
436 | pixels.show();
437 | delay(80);
438 | pixels.clear();
439 | pixels.show();
440 | delay(80);
441 | pixels.setPixelColor(0, pixels.Color(0, 255, 0));
442 | pixels.show();
443 | delay(80);
444 | pixels.clear();
445 | pixels.show();
446 | delay(80);
447 | pixels.setPixelColor(0, pixels.Color(0, 255, 0));
448 | pixels.show();
449 | delay(80);
450 | pixels.clear();
451 | pixels.show();
452 | }
453 | void flashalertred () { // radmon update failed
454 | pixels.clear();
455 | pixels.setPixelColor(0, pixels.Color(255, 0, 0));
456 | pixels.show();
457 | delay(80);
458 | pixels.clear();
459 | pixels.show();
460 | delay(80);
461 | pixels.setPixelColor(0, pixels.Color(255, 0, 0));
462 | pixels.show();
463 | delay(80);
464 | pixels.clear();
465 | pixels.show();
466 | delay(80);
467 | pixels.setPixelColor(0, pixels.Color(255, 0, 0));
468 | pixels.show();
469 | delay(80);
470 | pixels.clear();
471 | pixels.show();
472 | }
473 | void flashblue () { // flash blue NeoPixel HeartBeat for every serial EOL received ( should be 1 sec )
474 | pixels.clear();
475 | pixels.setPixelColor(0, pixels.Color(0, 0, 255));
476 | pixels.show();
477 | delay(80);
478 | pixels.clear();
479 | pixels.show();
480 | }
481 | void flashred () { // flash red LED CPS times
482 | for (int i = 1; i <= cps; i++) {
483 | digitalWrite(13, HIGH); // Flash red LED * cps
484 | delay(40);
485 | digitalWrite(13, LOW);
486 | delay(40);
487 | }
488 | }
489 | void handleRootPath() { // Web diagnostics page
490 | server.send(200, "text/plain", Release + ("\n") + (
491 | ReleaseDate) + ("\n") + (
492 | "Hardware: Feather Huzzah ESP32 v2") + ("\n") + ("\n") + (
493 | " ________ __ ____ __") + ("\n") + (
494 | "| | | || |_ .--.--.|_ / .-----. .-----.-----.| |_") + ("\n") + (
495 | "| | | || || | | / /_ | - | _ | | -__|| _|") + ("\n") + (
496 | "|________||__|_||__ ||____||___|_||_||__|__|_____||____|") + ("\n") + (
497 | " |__| ") + ("\n") + ("\n") + (
498 | timeClient.getFormattedTime()) + ("\n") + (
499 | "Uptime: ") + (uptime_formatter::getUptime()) + ("\n") + ("\n") + (
500 | "Geiger Connected: ") + geigerconnected + (" ") + ("\n") + ("\n") + (
501 | "Rolling Average CPM: ") + uploadcpm + ("\n") + (
502 | "Rolling 1 hour Average CPM: ") + cpmhour + ("\n") + ("\n") + (
503 | "uSieverts/Hour: ") + sieverts + ("\n") + (
504 | "mSieverts/Year: ") + svyear + ("\n") + ("\n") + (
505 | "Last Radmon Update(secs): ") + ((millis() - uploaddelay) / 1000) + ("\n") + (
506 | "Radmon HTTP Get status code: ") + statusCode + ("\n") + (
507 | "Last Upload Delay(ms): ") + timertotal + ("\n") + (
508 | "Rolling 1 hour Average Upload Delay(ms): ") + timeravg + ("\n") + (
509 | "Rolling 1 day Average Upload Delay(ms): ") + timerdayavg + ("\n") + (
510 | "Last Radmon Update CPM: ") + lastupdate + ("\n\n") + (
511 | "Current Data:") + webdata + ("\n\n") + (
512 | "Debug:\n") + (
513 | "Scale: ") + scale + (" recenthi: ") + recenthi + (" xplot: ") + xplot + ("\n")
514 | );
515 | }
516 |
517 | void buttons () { // check for button presses
518 | if (millis() > (buttontimer + 500)) {
519 | buttontimer = millis();
520 | if (!digitalRead(buttonC) && (!digitalRead(buttonB))) { // Check if a button is pressed and change mode accordingly
521 | oldmode = mode;
522 | WIFIEnable = !WIFIEnable;
523 | mode = 5;
524 | gotButton = true;
525 | }
526 | else if (!digitalRead(buttonA)) {
527 | mode = (mode + 1);
528 | if (mode == 4 | mode == 5)
529 | mode = 1;
530 | gotButton = true;
531 | }
532 | else if (!digitalRead(buttonB)) {
533 | mode = 4;
534 | gotButton = true;
535 | }
536 | else if (!digitalRead(buttonC)) {
537 | mode = (mode - 1);
538 | if (mode == 0 ) {
539 | mode = 3;
540 | }
541 | gotButton = true;
542 | }
543 |
544 | if (gotButton)
545 | delay(25); // Debounce
546 | switch (mode) { // Display current mode
547 | case 1: // All data and graph ( max 110 cpm )
548 | smallData();
549 | break;
550 | case 2: // Geiger data and graph ( max 110 cpm )
551 | mediumData();
552 | break;
553 | case 3: // Large count stats and background graph ( max 28 cpm )
554 | largeData();
555 | break;
556 | case 5: //Toggle WIFI on/off - Buttons B&C
557 | toggleWiFi();
558 | break;
559 | case 4: //Graph Data, autoscale max 16, 32, 64, 128, 256
560 | histogramData();
561 | break;
562 | }
563 | }
564 | }
565 | void smallData () { // All data and graph ( max 110 cpm )
566 | oled.clearDisplay();
567 | oled.setCursor(0, 0);
568 | oled.setTextSize(1);
569 | oled.print("HTTP Get:");
570 | if (statusCode >= 999 )
571 | statusCode = 0;
572 | oled.print(statusCode);
573 | oled.setCursor(80, 0);
574 | oled.println(timeClient.getFormattedTime());
575 | oled.print("WiFi:");
576 | if (WiFi.status() != WL_CONNECTED)
577 | oled.println("N/A");
578 | else
579 | oled.println(WiFi.localIP());
580 | oled.setTextSize(2);
581 | oled.print("CPS:");
582 | oled.print(cps);
583 | oled.setTextSize(1);
584 | if ( cpm < 1000) {
585 | oled.setCursor(67, 16);
586 | }
587 | else {
588 | oled.setCursor(79, 16);
589 | }
590 | oled.print(" A:");
591 | oled.print(uploadcpm);
592 | oled.setCursor(127, 0);
593 | oled.setTextSize(2);
594 | oled.println();
595 | oled.println();
596 | oled.print("CPM:");
597 | if (cpm >= 1) {
598 | oled.println(cpm);
599 | }
600 | oled.setTextSize(1);
601 | oled.print("uSieverts/Hour:");
602 | oled.println(sieverts);
603 | oled.print("mSieverts/Year:");
604 | oled.println(svyear);
605 | if ( cpm < 1000) {
606 | if (cpm >= 110) {
607 | barz = 7;
608 | } else if (cpm < 110 & cpm >= 35) {
609 | barz = 6;
610 | } else if (cpm < 35 & cpm >= 28) {
611 | barz = 5;
612 | } else if (cpm < 28 & cpm >= 23) {
613 | barz = 4;
614 | } else if (cpm < 23 & cpm >= 18) {
615 | barz = 3;
616 | } else if (cpm < 18 & cpm >= 13) {
617 | barz = 2;
618 | } else if (cpm < 13 & cpm >= 9) {
619 | barz = 1;
620 | } else {
621 | barz = 0;
622 | }
623 | for (int b = 0; b <= barz; b++) {
624 | oled.fillRect(90 + (b * 5), 43 - (b * 5), 3, b * 5, WHITE);
625 | }
626 | }
627 | oled.display();
628 | }
629 | void mediumData () { // Geiger data and graph ( max 110 cpm )
630 | oled.clearDisplay();
631 | oled.setCursor(0, 0);
632 | oled.setTextSize(1);
633 | oled.print("uSv/hr:");
634 | oled.print(sieverts);
635 | oled.setCursor(72, 0);
636 | oled.print("Avg:");
637 | oled.println(uploadcpm);
638 | oled.setCursor(0, 16);
639 | oled.setTextSize(1);
640 | oled.print("CPS: ");
641 | oled.setCursor(30, 8);
642 | oled.setTextSize(3);
643 | oled.println(cps);
644 | oled.setTextSize(1);
645 | oled.print("mSv/yr:");
646 | oled.println(svyear);
647 | oled.setTextSize(3);
648 | if (cpm >= 1) {
649 | oled.setCursor(0, 48);
650 | oled.setTextSize(1);
651 | oled.print("CPM: ");
652 | }
653 | oled.setCursor(30, 40);
654 | oled.setTextSize(3);
655 | oled.println(cpm);
656 | if (cpm >= 110) {
657 | barz = 7;
658 | } else if (cpm < 110 & cpm >= 35) {
659 | barz = 6;
660 | } else if (cpm < 35 & cpm >= 28) {
661 | barz = 5;
662 | } else if (cpm < 28 & cpm >= 23) {
663 | barz = 4;
664 | } else if (cpm < 23 & cpm >= 18) {
665 | barz = 3;
666 | } else if (cpm < 18 & cpm >= 13) {
667 | barz = 2;
668 | } else if (cpm < 13 & cpm >= 9) {
669 | barz = 1;
670 | } else {
671 | barz = 0;
672 | }
673 | for (int b = 0; b <= barz; b++) {
674 | oled.fillRect(90 + (b * 5), 35 - (b * 5), 3, b * 5, WHITE);
675 | }
676 | oled.display();
677 | }
678 | void largeData () { // Large count stats and background graph ( max 28 cpm )
679 | if ( cpm >= 1000) {
680 | oled.clearDisplay();
681 | oled.setCursor(0, 0);
682 | oled.setTextSize(4);
683 | if (cpm >= 1) {
684 | oled.print(cps);
685 | }
686 | oled.setTextSize(1);
687 | oled.setCursor(75, 0);
688 | oled.println(timeClient.getFormattedTime());
689 | oled.setCursor(75, 8);
690 | if (statusCode >= 999 )
691 | statusCode = 0;
692 | oled.print("U/L:");
693 | oled.println(statusCode);
694 | oled.setCursor(75, 16);
695 | oled.print("Avg:");
696 | oled.print(uploadcpm);
697 | oled.setCursor(127, 0);
698 | oled.setTextSize(4);
699 | oled.println();
700 | oled.println(cpm);
701 | oled.display();
702 | }
703 | else {
704 | oled.clearDisplay();
705 | oled.setCursor(0, 0);
706 | oled.setTextSize(4);
707 | if (cpm >= 1) {
708 | oled.print(cpm);
709 | }
710 | oled.setTextSize(1);
711 | oled.setCursor(69, 0);
712 | oled.println(timeClient.getFormattedTime());
713 | oled.setCursor(69, 8);
714 | if (statusCode >= 999 )
715 | statusCode = 0;
716 | oled.println(statusCode);
717 | oled.setCursor(69, 16);
718 | oled.print(uploadcpm);
719 | oled.setCursor(127, 0);
720 | oled.setTextSize(4);
721 | oled.println();
722 | oled.println(cps);
723 | if (cpm >= 28) {
724 | barz = 19;
725 | } else if (cpm < 28 & cpm >= 27) {
726 | barz = 18;
727 | } else if (cpm < 27 & cpm >= 26) {
728 | barz = 17;
729 | } else if (cpm < 26 & cpm >= 24) {
730 | barz = 16;
731 | } else if (cpm < 24 & cpm >= 23) {
732 | barz = 15;
733 | } else if (cpm < 23 & cpm >= 22) {
734 | barz = 14;
735 | } else if (cpm < 22 & cpm >= 21) {
736 | barz = 13;
737 | } else if (cpm < 21 & cpm >= 20) {
738 | barz = 12;
739 | } else if (cpm < 20 & cpm >= 19) {
740 | barz = 11;
741 | } else if (cpm < 19 & cpm >= 18) {
742 | barz = 10;
743 | } else if (cpm < 18 & cpm >= 17) {
744 | barz = 9;
745 | } else if (cpm < 17 & cpm >= 16) {
746 | barz = 8;
747 | } else if (cpm < 16 & cpm >= 15) {
748 | barz = 7;
749 | } else if (cpm < 15 & cpm >= 14) {
750 | barz = 6;
751 | } else if (cpm < 14 & cpm >= 13) {
752 | barz = 5;
753 | } else if (cpm < 13 & cpm >= 12) {
754 | barz = 4;
755 | } else if (cpm < 12 & cpm >= 11) {
756 | barz = 3;
757 | } else if (cpm < 11 & cpm >= 10) {
758 | barz = 2;
759 | } else if (cpm < 10 & cpm >= 9) {
760 | barz = 1;
761 | } else {
762 | barz = 0;
763 | }
764 | for (int b = 0; b <= barz; b++) {
765 | oled.fillRect(27 + (b * 5), 60 - (b * 3), 3, b * 3, WHITE);
766 | }
767 | oled.display();
768 | }
769 | }
770 |
771 | void toggleWiFi () { //Toggle WIFI on/off
772 | if (WIFIEnable == 1 )
773 | wifion();
774 | if (WIFIEnable == 0 ) {
775 | wifioff();
776 | stopWiFiAndSleep();
777 | }
778 | oled.clearDisplay();
779 | mode = oldmode;
780 | }
781 | void histogramData () { //Graph Data, autoscale max 16, 32, 64, 128, 256
782 | oled.clearDisplay();
783 | oled.setTextSize(1);
784 | oled.setCursor(36, 0);
785 | // oled.print("mSv/y: ");
786 | oled.println(svyear);
787 | oled.setCursor(80, 0);
788 | oled.println(timeClient.getFormattedTime());
789 | if (recenthi == 14) {
790 | scale = 0.000488281 ;
791 | } else if (recenthi == 13) {
792 | scale = 0.000976562 ;
793 | } else if (recenthi == 12) {
794 | scale = 0.001953125 ;
795 | } else if (recenthi == 11) {
796 | scale = 0.00390625 ;
797 | } else if (recenthi == 10) {
798 | scale = 0.0078125 ;
799 | } else if (recenthi == 9) {
800 | scale = 0.015625 ;
801 | } else if (recenthi == 8) {
802 | scale = 0.03125 ;
803 | } else if (recenthi == 7) {
804 | scale = 0.0625 ;
805 | } else if (recenthi == 6) {
806 | scale = 0.125 ;
807 | } else if (recenthi == 5) {
808 | scale = 0.25 ;
809 | } else if (recenthi == 4) {
810 | scale = 0.5 ;
811 | } else if (recenthi == 3) {
812 | scale = 1 ;
813 | } else if (recenthi == 2) {
814 | scale = 2;
815 | } else if (recenthi == 1) {
816 | scale = 4;
817 | } else if (recenthi == 0) {
818 | scale = 8;
819 | }
820 | for (decltype(xpoints)::index_t i = 0; i <= xpoints.size(); i++) {
821 | oled.fillRect( i + 12 , 65 - (int(scale * xpoints[i])) , 1 , (int(scale * xpoints[i])) , WHITE);
822 | // Serial.print(xpoints[i]);
823 | // Serial.println(int(scale * xpoints[i]));
824 | for (decltype(xpoints)::index_t i = 0; i <= xpoints.size(); i++) {
825 | if (xpoints[i] >= 65537 ) {
826 | recenthi = 14;
827 | scale14 = true;
828 | }
829 | if ( xpoints[i] < 65537 && xpoints[i] >= 32769 && scale14 == false ) {
830 | recenthi = 13;
831 | scale13 = true;
832 | }
833 | if ( xpoints[i] < 32769 && xpoints[i] >= 16385 && scale14 == false && scale13 == false ) {
834 | recenthi = 12;
835 | scale12 = true;
836 | }
837 | if ( xpoints[i] < 16385 && xpoints[i] >= 8193 && scale14 == false && scale13 == false && scale12 == false ) {
838 | recenthi = 11;
839 | scale11 = true;
840 | }
841 | if ( xpoints[i] < 8193 && xpoints[i] >= 4097 && scale14 == false && scale13 == false && scale12 == false && scale11 == false ) {
842 | recenthi = 10;
843 | scale10 = true;
844 | }
845 | if ( xpoints[i] < 4097 && xpoints[i] >= 2049 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false ) {
846 | recenthi = 9;
847 | scale9 = true;
848 | }
849 | if ( xpoints[i] < 2049 && xpoints[i] >= 1025 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false ) {
850 | recenthi = 8;
851 | scale8 = true;
852 | }
853 | if ( xpoints[i] < 1025 && xpoints[i] >= 513 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false ) {
854 | recenthi = 7;
855 | scale7 = true;
856 | }
857 | if ( xpoints[i] < 513 && xpoints[i] >= 257 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false ) {
858 | recenthi = 6;
859 | scale6 = true;
860 | }
861 | if ( xpoints[i] < 257 && xpoints[i] >= 129 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false ) {
862 | recenthi = 5;
863 | scale5 = true;
864 | }
865 | if ( xpoints[i] < 129 && xpoints[i] >= 65 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false ) {
866 | recenthi = 4;
867 | scale4 = true;
868 | }
869 | if ( xpoints[i] < 65 && xpoints[i] >= 33 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false && scale4 == false ) {
870 | recenthi = 3;
871 | scale3 = true;
872 | }
873 | if ( xpoints[i] < 33 && xpoints[i] >= 17 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false && scale4 == false && scale3 == false ) {
874 | recenthi = 2;
875 | scale2 = true;
876 | }
877 | if ( xpoints[i] < 17 && xpoints[i] >= 9 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false && scale4 == false && scale3 == false && scale2 == false ) {
878 | recenthi = 1;
879 | scale1 = true;
880 | }
881 | if ( xpoints[i] < 9 && xpoints[i] >= 1 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false && scale4 == false && scale3 == false && scale2 == false && scale1 == false ) {
882 | recenthi = 0;
883 | scale0 = true;
884 | }
885 | }
886 | oled.setTextColor(WHITE);
887 | oled.setTextSize(1);
888 | oled.setCursor(0, 0);
889 | if ((int(64 / scale) > 1023 )) {
890 | sprintf(buffer, "%dK", int(64 / scale / 1024));
891 | oled.print(buffer);
892 | }
893 | else {
894 | oled.print(int(64 / scale));
895 | }
896 | oled.setCursor(0, 14);
897 | if ((int(48 / scale) == 1536 )) {
898 | oled.print("1.5K");
899 | }
900 | if ((int(48 / scale) > 1536 )) {
901 | sprintf(buffer, "%dK", int(48 / scale / 1024));
902 | oled.print(buffer);
903 | }
904 | if ((int(48 / scale) < 1536 )) {
905 | oled.print(int(48 / scale));
906 | }
907 | oled.setCursor(0, 28);
908 | if ((int(32 / scale) > 1023 )) {
909 | sprintf(buffer, "%dK", int(32 / scale / 1024));
910 | oled.print(buffer);
911 | }
912 | else {
913 | oled.print(int(32 / scale));
914 | }
915 | oled.setCursor(0, 42);
916 | if ((int(16 / scale) > 1023 )) {
917 | sprintf(buffer, "%dK", int(16 / scale / 1024));
918 | oled.print(buffer);
919 | }
920 | else
921 | oled.print(int(16 / scale));
922 | oled.setCursor(0, 57);
923 | oled.print("0");
924 | oled.setTextColor(BLACK);
925 | oled.setCursor(14, 48);
926 | oled.setTextSize(2);
927 | oled.print(cps);
928 | if ( cps < 100 ) {
929 | oled.setTextSize(1);
930 | oled.print("CPS");
931 | }
932 | oled.setCursor(58, 48);
933 | oled.setTextSize(2);
934 | if (xplot >= 1); {
935 | oled.print(xplot);
936 | }
937 | oled.setTextSize(1);
938 | oled.print("CPM");
939 | oled.setCursor(115, 55);
940 | // oled.print("U/L:");
941 | if ((statusCode) == 200) {
942 | oled.print("OK");
943 | }
944 | // else {
945 | // oled.print("NA");
946 | // }
947 | }
948 | scale0 = false;
949 | scale1 = false;
950 | scale2 = false;
951 | scale3 = false;
952 | scale4 = false;
953 | scale5 = false;
954 | scale6 = false;
955 | scale7 = false;
956 | scale8 = false;
957 | scale9 = false;
958 | scale10 = false;
959 | scale11 = false;
960 | scale12 = false;
961 | scale13 = false;
962 | scale14 = false;
963 | oled.setTextColor(WHITE);
964 | oled.display();
965 | }
966 |
967 | //Monitor the serial connection from the geiger counter.
968 | //If it is absent for > 15 seconds, display a warning
969 | void serialmon () {
970 | if (millis() > (geigerTimeout + 15000)) {
971 | geigerConnected = false;
972 | geigerconnected = ("false");
973 | oled.clearDisplay();
974 | oled.setTextSize(1);
975 | oled.setCursor(0, 0);
976 | oled.println(Release);
977 | sprintf(buffer, "\nSerial NOT CONNECTED! \nCheck uart connection \nGPIO 27, # 6 on top from L to R");
978 | oled.print(buffer);
979 | oled.display();
980 | APP_NAME = "serialmon: ";
981 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
982 | syslog.log(LOG_INFO, "Geiger not connected! - Check serial port");
983 | geigerTimeout = millis();
984 | delay(3000);
985 | }
986 | }
987 | //***Grab, store and write softSerial data from GPIO 27 to USB serial port*****
988 | void grab() {
989 | if (mySerial.available()) {
990 | geigerdata = (mySerial.read());
991 | // if (Serial1.available()) {
992 | // geigerdata = (Serial1.read());
993 | geigerSerial += char(geigerdata);
994 | delay(1);
995 | }
996 | }
997 | //****Process data****
998 | void process() {
999 | if (geigerdata == 0x0D) { // EOL detected
1000 | Log.loop();
1001 | geigerConnected = true; // Record that serial connection health is ok
1002 | geigerconnected = ("true");
1003 | geigerTimeout = millis();
1004 | // Parse CPS, CPM, and uS/hr from the string
1005 | int comma1Index = geigerSerial.indexOf(',');
1006 | int comma2Index = geigerSerial.indexOf(',', comma1Index + 1);
1007 | int comma3Index = geigerSerial.indexOf(',', comma2Index + 1);
1008 | int comma4Index = geigerSerial.indexOf(',', comma3Index + 1);
1009 | int comma5Index = geigerSerial.indexOf(',', comma4Index + 1);
1010 | int comma6Index = geigerSerial.indexOf(',', comma5Index + 1);
1011 | String cpsString = geigerSerial.substring(comma1Index + 1, comma2Index);
1012 | String cpmString = geigerSerial.substring(comma3Index + 1, comma4Index);
1013 | String sievertsString = geigerSerial.substring(comma5Index + 1, comma6Index);
1014 | cps = cpsString.toInt();
1015 | cpm = cpmString.toInt();
1016 | sieverts = sievertsString.toFloat();
1017 | webdata = geigerSerial;
1018 | Log.print(geigerSerial);
1019 | svyear = (sieverts * 8.76);
1020 | averagedata(); // get data averages
1021 | // grabgraphdata(); // grab data for mode 5 graph
1022 | geigerSerial = ""; // Clear the string for next time
1023 | flashblue (); // Heartbeat pulse
1024 | if (cps <= 5)
1025 | flashred (); // Flash red LED * CPS
1026 | else
1027 | digitalWrite(13, HIGH);
1028 | }
1029 | }
1030 |
1031 | // ********Setup*******
1032 | void setup() {
1033 | pinMode(13, OUTPUT); // setup LEDs
1034 | pinMode(0, OUTPUT); // setup LEDs
1035 | digitalWrite(0, LOW); // setup LEDs
1036 | digitalWrite(13, LOW); // setup LED
1037 | pinMode(buttonA, INPUT_PULLUP);
1038 | pinMode(buttonB, INPUT_PULLUP);
1039 | pinMode(buttonC, INPUT_PULLUP);
1040 | mySerial.begin(9600); // Start software serial link from Gieger
1041 | // Serial1.begin(9600); // Start hardware serial console
1042 | Serial.begin(115200); // Start hardware serial console
1043 | while (!Serial)
1044 | ; // wait for serial port to connect. Needed for Native USB only
1045 |
1046 | oled.init();
1047 | oled.setContrast (contrast); // reduce contrast to preserve OLED display
1048 |
1049 | // Animate bitmap
1050 | for (int i = -1; i <= 10; i++) {
1051 | oled.clearDisplay();
1052 | oled.drawBitmap(0, (62 - (6 * i)), bootupbitmap, 128, 60, WHITE);
1053 | oled.display();
1054 | }
1055 | delay (1500);
1056 |
1057 | Log.addPrintStream(std::make_shared(telnetSerialStream));
1058 | Log.addPrintStream(std::make_shared(webSerialStream));
1059 | wifion(); // Start wifi if enabled
1060 | Log.begin();
1061 | APP_NAME = "setup: ";
1062 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
1063 | syslog.log(LOG_INFO, "Initial setup successful");
1064 | cpmminavg.begin(); // Init moving average
1065 | cpmhouravg.begin(); // Init moving average
1066 | timerdelayavg.begin(); // Init moving average
1067 | timerdelaydayavg.begin(); // Init moving average
1068 | pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
1069 | if (radmonen == true ) {
1070 | xTaskCreatePinnedToCore(
1071 | radmon, /* Task function. */ // Upload to radmon.org every 60 secs using CPU0 as the HTTP GET takes some time
1072 | "Task1", /* name of task. */
1073 | 10000, /* Stack size of task */
1074 | NULL, /* parameter of the task */
1075 | 1, /* priority of the task */
1076 | &Task1, /* Task handle to keep track of created task */
1077 | 0); /* pin task to core 0 */
1078 | }
1079 | xTaskCreatePinnedToCore(
1080 | randomise, /* Task function. */
1081 | "Task2", /* name of task. */
1082 | 10000, /* Stack size of task */
1083 | NULL, /* parameter of the task */
1084 | 1, /* priority of the task */
1085 | &Task2, /* Task handle to keep track of created task */
1086 | 0); /* pin task to core 0 */
1087 |
1088 | if (randomon == true ) {
1089 | pinMode(pulsepin, INPUT_PULLUP);
1090 | attachInterrupt(digitalPinToInterrupt(pulsepin), grabrandomnum, RISING);
1091 | }
1092 | }
1093 |
1094 | // ****Main Loop****
1095 | void loop() {
1096 | serialmon(); // Monitor serial port for disconnection
1097 | grab(); // Grab MightyOhm serial data
1098 | process(); // Extract data and process
1099 | server.handleClient(); // Start Web diagnostics & data server on http://localip:80
1100 | logstats(); // Send hourly stats to syslog server
1101 | buttons(); // wait for button input and action
1102 | runntp(); // update NTP if setUpdateInterval in millis has expired
1103 | grabgraphdata(); // grab data for mode 4 histogram graph
1104 | if (randomon == true ) {
1105 | echorandom ();
1106 | }
1107 | }
1108 |
--------------------------------------------------------------------------------
/WhyzaGC-3.5-ESP8266-release.ino:
--------------------------------------------------------------------------------
1 | // Latest version available https://github.com/Whyzanet/WhyzaGC
2 | const char* release = "WhyzaGC v3.5";
3 | const char* releasedate = "Released 3/11/2022";
4 |
5 | bool WIFIEnable = true; // set startup wifi client behaviour
6 | const char* ssid = "CHANGEME"; // Set wifi SSID
7 | const char* password = "CHANGEME"; // Set wifi password
8 | int TZ = +10; // Set local timezone offset from UTC CHANGEME
9 | bool radmonen = true; // Set startup radmon.org behaviour. Will enable WIFI if reqd
10 | const char* radmonuser = "CHANGEME"; // Set radmon.org username
11 | const char* radmonpass = "CHANGEME"; // Set radmon.org password
12 | const char* ntpServer = "pool.ntp.org"; // Set ntp server
13 | const char* hostname = "WhyzaGC-ESP";
14 | uint8_t mode = 5; // Startup default OLED display mode - Histogram Display ( Buttons A&B )
15 | #include
16 | SoftwareSerial mySerial(13, 14); // Gieger serial port directly connected on RX, TX ( no TX connection needed as only receiving data )
17 | #include
18 | #define SYSLOG_SERVER "192.168.0.138" // Set syslog server CHANGEME
19 | #define SYSLOG_PORT 514 // Syslog port
20 | #define DEVICE_HOSTNAME "WhyzaGC-ESP" // Set syslog hostname
21 | const char* APP_NAME = "my-function";
22 | #include
23 | ESP8266WebServer server(80); // Set web server port
24 | int contrast = 0; // reduce OLED contrast to preserve OLED lifespan
25 | bool randomon = false; // enable random number generator
26 | int pulsepin = 12;
27 |
28 | // ********************************************************************************************************************
29 | // ****** ESP8266 requires compile option CPU Frequency to be set to 160Mhz to accomodate high values of CPS/CPM *****
30 | // ********************************************************************************************************************
31 |
32 | #include // The T-Logging library.
33 | // Run a telnet service on the default port (23) which shows what is
34 | // sent to Serial if you telnet to it.
35 | //
36 | #include
37 | TelnetSerialStream telnetSerialStream = TelnetSerialStream();
38 | // Likewise let http://:81/ show the log in a webbrowser.
39 | //
40 | #include
41 | WebSerialStream webSerialStream = WebSerialStream(81);
42 |
43 | #include
44 | const char* serverIndex = "";
45 | #include
46 | #include
47 | #include
48 | #include
49 | #include
50 | #include
51 | #include
52 | #include
53 | #include
54 | #include "uptime_formatter.h"
55 | #include // Histogram data
56 | #define buttonA 0
57 | #define buttonB 16
58 | #define buttonC 2
59 | Adafruit_FeatherOLED_SH110X oled = Adafruit_FeatherOLED_SH110X();
60 | WiFiUDP ntpUDP;
61 | NTPClient timeClient(ntpUDP, ntpServer);
62 | WiFiUDP udpClient;
63 | movingAvg cpmminavg(60);
64 | movingAvg cpmhouravg(3600);
65 | movingAvg timerdelayavg(60);
66 | movingAvg timerdelaydayavg(1440);
67 | CircularBuffer xpoints; // mode 5 histogram graph data
68 | unsigned long uploadcpm = 0;
69 | unsigned long cpmhour = 0;
70 | unsigned long uploaddelay = 0; // measure the radmon upload time. Updated Gieger Serial data over this period will be lost.
71 | unsigned long lastupdate = 0;
72 | unsigned long avgdelay = 0;
73 | unsigned long logdelay = 0;
74 | unsigned long timeravg = 0;
75 | unsigned long timerdayavg = 0;
76 | unsigned long buttontimer = 0;
77 | String Release = release;
78 | String ReleaseDate = releasedate;
79 | String Hostname = hostname;
80 | int statusCode = 0;
81 | uint8_t oldmode;
82 | bool geigerConnected = false;
83 | String geigerconnected;
84 | unsigned long geigerTimeout = 0;
85 | bool gotButton = false;
86 | String geigerSerial;
87 | unsigned char geigerdata;
88 | String webdata;
89 | int barz;
90 | int cps = 0;
91 | int cpm = 0;
92 | int xsize = 0;
93 | int xplot = 0;
94 | float sieverts = 0;
95 | float svyear = 0;
96 | float battery = oled.getBatteryVoltage();
97 | char buffer[255];
98 | unsigned long timer = 0;
99 | unsigned long timertotal = 0;
100 | float scale = 0; // mode 5 graph scaling
101 | int recenthi = 0;
102 | int previoushi = 0;
103 | bool scale0 = false;
104 | bool scale1 = false;
105 | bool scale2 = false;
106 | bool scale3 = false;
107 | bool scale4 = false;
108 | bool scale5 = false;
109 | bool scale6 = false;
110 | bool scale7 = false;
111 | bool scale8 = false;
112 | bool scale9 = false;
113 | bool scale10 = false;
114 | bool scale11 = false;
115 | bool scale12 = false;
116 | bool scale13 = false;
117 | bool scale14 = false;
118 | unsigned long grabgraphdatadelay = 0;
119 | int randomresult = -1;
120 | int gotrandomresult = 0x00;
121 | int printrandomresult = 0x00;
122 | bool newrandom = false;
123 |
124 | const unsigned char bootupbitmap [] PROGMEM = {
125 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
126 | 0x00, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
127 | 0x00, 0x00, 0x07, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
128 | 0x00, 0x00, 0x1f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
129 | 0x00, 0x00, 0x7f, 0x00, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130 | 0x00, 0x01, 0xf8, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
131 | 0x00, 0x07, 0xe0, 0x7f, 0xe0, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132 | 0x00, 0x0f, 0x83, 0xff, 0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133 | 0x00, 0x1e, 0x1f, 0xff, 0xff, 0x87, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134 | 0x00, 0x3c, 0x1f, 0xff, 0xff, 0xc1, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
135 | 0x00, 0x78, 0x1f, 0xff, 0xff, 0x80, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136 | 0x00, 0xf0, 0x0f, 0xff, 0xff, 0x80, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137 | 0x01, 0xe0, 0x0f, 0xff, 0xff, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138 | 0x01, 0xc0, 0x07, 0xff, 0xff, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
139 | 0x03, 0x80, 0x03, 0xff, 0xfe, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140 | 0x07, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
141 | 0x07, 0x00, 0x01, 0xff, 0xfc, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
142 | 0x0e, 0x00, 0x01, 0xff, 0xf8, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
143 | 0x0e, 0x00, 0x00, 0xff, 0xf8, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
144 | 0x1c, 0x00, 0x00, 0xff, 0xf0, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
145 | 0x1c, 0x00, 0x00, 0x7f, 0xf0, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
146 | 0x18, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
147 | 0x38, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
148 | 0x38, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
149 | 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
150 | 0x30, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe0, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
151 | 0x30, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x00, 0xe0, 0xe7, 0x3b, 0x80, 0x00, 0x00, 0x01, 0xfc, 0x7f,
152 | 0x30, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x00, 0xe0, 0xe7, 0xbb, 0x80, 0x00, 0x00, 0x03, 0xfc, 0xff,
153 | 0x70, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0xe0, 0xff, 0xbb, 0xfb, 0x9f, 0xfb, 0xf7, 0x81, 0xe0,
154 | 0x70, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x60, 0x7f, 0xfb, 0xfb, 0xbc, 0x78, 0xf7, 0x81, 0xe0,
155 | 0x73, 0xff, 0xfe, 0x7f, 0xe7, 0xff, 0xfc, 0x60, 0x7f, 0xf3, 0xbb, 0xf8, 0xf8, 0x3f, 0x3d, 0xc0,
156 | 0x73, 0xff, 0xff, 0x7f, 0xe7, 0xff, 0xfc, 0xe0, 0x7d, 0xf3, 0xb9, 0xf9, 0xf7, 0xff, 0x9d, 0xe0,
157 | 0x33, 0xff, 0xff, 0x3f, 0xe7, 0xff, 0xfc, 0xe0, 0x7d, 0xf3, 0xb9, 0xfb, 0xe7, 0xff, 0x9d, 0xe0,
158 | 0x31, 0xff, 0xff, 0x1f, 0xcf, 0xff, 0xfc, 0xe0, 0x3d, 0xf3, 0xb8, 0xf3, 0xc7, 0xfb, 0xfc, 0xff,
159 | 0x31, 0xff, 0xff, 0x8f, 0x8f, 0xff, 0xfc, 0xe0, 0x3c, 0xe3, 0xb8, 0xf3, 0xff, 0xf9, 0xfc, 0x7f,
160 | 0x39, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xfc, 0xe0, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00,
161 | 0x39, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xf8, 0xc0, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00,
162 | 0x39, 0xff, 0xff, 0xc0, 0x1f, 0xff, 0xf9, 0xc0, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00,
163 | 0x18, 0xff, 0xff, 0x80, 0x1f, 0xff, 0xf9, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
164 | 0x1c, 0xff, 0xff, 0x80, 0x0f, 0xff, 0xf1, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
165 | 0x1c, 0x7f, 0xff, 0x00, 0x07, 0xff, 0xf3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
166 | 0x0e, 0x7f, 0xfe, 0x00, 0x07, 0xff, 0xe3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167 | 0x0e, 0x3f, 0xfe, 0x00, 0x03, 0xff, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
168 | 0x07, 0x3f, 0xfc, 0x00, 0x03, 0xff, 0xc7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
169 | 0x07, 0x1f, 0xfc, 0x00, 0x01, 0xff, 0x8e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
170 | 0x03, 0x8f, 0xf8, 0x00, 0x01, 0xff, 0x9e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
171 | 0x01, 0xc7, 0xf8, 0x00, 0x00, 0xff, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
172 | 0x01, 0xe3, 0xf0, 0x00, 0x00, 0x7e, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
173 | 0x00, 0xf1, 0xe0, 0x00, 0x00, 0x7c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
174 | 0x00, 0x78, 0xe0, 0x00, 0x00, 0x30, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
175 | 0x00, 0x3c, 0x00, 0x00, 0x00, 0x21, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
176 | 0x00, 0x1e, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
177 | 0x00, 0x0f, 0x80, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
178 | 0x00, 0x07, 0xe0, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
179 | 0x00, 0x01, 0xf8, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180 | 0x00, 0x00, 0x7f, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
181 | 0x00, 0x00, 0x1f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
182 | 0x00, 0x00, 0x07, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
183 | 0x00, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
184 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
185 | };
186 |
187 | //***Functions***
188 |
189 | void randomise () {
190 |
191 | if (randomresult == 0xF) {
192 | randomresult = 0;
193 | delay (1);
194 | }
195 | else {
196 | randomresult = (randomresult + 1);
197 | delay (1);
198 | }
199 | }
200 |
201 | ICACHE_RAM_ATTR void grabrandomnum () {
202 | detachInterrupt(pulsepin);
203 | newrandom = true;
204 | gotrandomresult = ( randomresult );
205 | attachInterrupt((pulsepin), grabrandomnum, RISING);
206 | }
207 |
208 | void echorandom () {
209 | if (newrandom == true) {
210 | Log.println("");
211 | Log.printf("%01x", gotrandomresult);
212 | newrandom = false;
213 | }
214 | }
215 |
216 |
217 | void grabgraphdata () { // grab histogram graph data for mode 5 display
218 | if (millis() > (grabgraphdatadelay + 1000)) {
219 | // if (cpm >= 1) {
220 | xpoints.push(cpm);
221 | xsize = xpoints.size();
222 | xplot = xpoints.last();
223 |
224 | // for (decltype(xpoints)::index_t i = 0; i < xpoints.size(); i++) {
225 | // Serial.print(xpoints[i]);
226 | // }
227 | // Serial.println(" ");
228 | grabgraphdatadelay = millis();
229 | }
230 | }
231 | void logstats () { // remote syslog status
232 | if (millis() > (logdelay + 3600000)) {
233 | APP_NAME = "logstats:";
234 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
235 | syslog.logf(LOG_INFO, "Latest 1 min average CPM: %d", uploadcpm);
236 | syslog.logf(LOG_INFO, "Latest 1 hour average CPM: %d", cpmhour);
237 | syslog.logf(LOG_INFO, "Latest HTTP response: %d", statusCode);
238 | logdelay = millis();
239 | }
240 | }
241 |
242 | void averagedata () {// calculate CPM data average for radmon upload
243 | if (millis() > (avgdelay + 550)) {
244 | uploadcpm = cpmminavg.reading(cpm);
245 | cpmhour = cpmhouravg.reading(cpm);
246 | avgdelay = millis();
247 | }
248 | }
249 | void radmon () {// perfrom the HTTP Get for radmon.org every minute
250 | if (radmonen == 1 && (geigerConnected == true)) {
251 | if (WIFIEnable == 0 || WiFi.status() != WL_CONNECTED) {
252 | statusCode = 0;
253 | }
254 | if (WIFIEnable == 1 && (millis() > (uploaddelay + 59999 - timertotal))) {
255 | if (WiFi.status() != WL_CONNECTED) {
256 | wifion();
257 | }
258 | else {
259 | String ptr = "/radmon.php?function=submit";
260 | ptr += "&user=";
261 | ptr += radmonuser;
262 | ptr += "&password=";
263 | ptr += radmonpass;
264 | ptr += "&value=";
265 | ptr += uploadcpm;
266 | ptr += "&unit=CPM";
267 | timer = (millis());
268 | WiFiClient wifi;
269 | HttpClient client = HttpClient(wifi, "www.radmon.org", 80);
270 | client.get(ptr);
271 | statusCode = client.responseStatusCode();
272 | lastupdate = uploadcpm;
273 | uploaddelay = millis();
274 | timertotal = (millis() - timer);
275 | // Serial.println(timertotal);
276 | timeravg = timerdelayavg.reading(timertotal);
277 | timerdayavg = timerdelaydayavg.reading(timertotal);
278 | // Serial.println(timeravg);
279 | }
280 | }
281 | }
282 | }
283 |
284 | void runntp () { // run the NTP client
285 | timeClient.update();
286 | //Serial.println(timeClient.getFormattedTime());
287 | //Serial.println(timeClient.getFormattedDate());
288 | }
289 | void flashblue () { // flash blue LED HeartBeat for every serial EOL received ( should be 1 sec )
290 | digitalWrite(2, LOW);
291 | delay(80);
292 | digitalWrite(2, HIGH);
293 | }
294 | void flashred () { // flash red LED CPS times
295 | for (int i = 1; i <= cps; i++) {
296 | digitalWrite(0, LOW); // Flash red LED * cps
297 | delay(40);
298 | digitalWrite(0, HIGH);
299 | delay(40);
300 | }
301 | }
302 | void handleRootPath() {// Web diagnositcs page
303 | server.send(200, "text/plain", Release + ("\n") + (
304 | ReleaseDate) + ("\n") + ("\n") + (
305 | "Hardware: Feather Huzzah ESP8266") + ("\n") + ("\n") + (
306 | " ________ __ ____ __") + ("\n") + (
307 | "| | | || |_ .--.--.|_ / .-----. .-----.-----.| |_") + ("\n") + (
308 | "| | | || || | | / /_ | - | _ | | -__|| _|") + ("\n") + (
309 | "|________||__|_||__ ||____||___|_||_||__|__|_____||____|") + ("\n") + (
310 | " |__| ") + ("\n") + ("\n") + (
311 | timeClient.getFormattedTime()) + ("\n") + (
312 | "Uptime: ") + (uptime_formatter::getUptime()) + ("\n") + ("\n") + (
313 | "Geiger Connected: ") + geigerconnected + (" ") + ("\n") + ("\n") + (
314 | "Rolling Average CPM: ") + uploadcpm + ("\n") + (
315 | "Rolling 1 hour Average CPM: ") + cpmhour + ("\n") + ("\n") + (
316 | "uSieverts/Hour: ") + sieverts + ("\n") + (
317 | "mSieverts/Year: ") + svyear + ("\n") + ("\n") + (
318 | "Last Radmon Update(secs): ") + ((millis() - uploaddelay) / 1000) + ("\n") + (
319 | "Radmon HTTP Get status code: ") + statusCode + ("\n") + (
320 | "Last Upload Delay(ms): ") + timertotal + ("\n") + (
321 | "Rolling 1 hour Average Upload Delay(ms): ") + timeravg + ("\n") + (
322 | "Rolling 1 day Average Upload Delay(ms): ") + timerdayavg + ("\n") + (
323 | "Last Radmon Update CPM: ") + lastupdate + ("\n\n") + (
324 | "Current Data:") + webdata + ("\n\n") + (
325 | "Debug:\n") + (
326 | "Scale: ") + scale + (" recenthi: ") + recenthi + (" xplot: ") + xplot + ("\n")
327 | );
328 | }
329 |
330 | void buttons () { // check for button presses
331 | if (millis() > (buttontimer + 500)) {
332 | buttontimer = millis();
333 | if (!digitalRead(buttonC) && (!digitalRead(buttonB))) { // Check if a button is pressed and change mode accordingly
334 | oldmode = mode;
335 | WIFIEnable = !WIFIEnable;
336 | mode = 5;
337 | gotButton = true;
338 | }
339 | else if (!digitalRead(buttonA)) {
340 | mode = (mode + 1);
341 | if (mode == 4 | mode == 5)
342 | mode = 1;
343 | gotButton = true;
344 | }
345 | else if (!digitalRead(buttonB)) {
346 | mode = 4;
347 | gotButton = true;
348 | }
349 | else if (!digitalRead(buttonC)) {
350 | mode = (mode - 1);
351 | if (mode == 0 ) {
352 | mode = 3;
353 | }
354 | gotButton = true;
355 | }
356 | if (gotButton)
357 | delay(25); // Debounce
358 | switch (mode) { // Display current mode
359 | case 1: // All data and graph ( max 110 cpm )
360 | smallData();
361 | break;
362 | case 2: // Geiger data and graph ( max 110 cpm )
363 | mediumData();
364 | break;
365 | case 3: // Large count stats and background graph ( max 28 cpm )
366 | largeData();
367 | break;
368 | case 5: //Toggle WIFI on/off - Buttons B&C
369 | toggleWiFi();
370 | break;
371 | case 4: //Graph Data, autoscale max 16, 32, 64, 128, 256
372 | histogramData();
373 | break;
374 | }
375 | }
376 | }
377 | void smallData () { // All data and graph ( max 110 cpm )
378 | oled.clearDisplay();
379 | oled.setCursor(0, 0);
380 | oled.setTextSize(1);
381 | oled.print("HTTP Get:");
382 | if (statusCode >= 999 )
383 | statusCode = 0;
384 | oled.print(statusCode);
385 | oled.setCursor(80, 0);
386 | oled.println(timeClient.getFormattedTime());
387 | oled.print("WiFi:");
388 | if (WiFi.status() != WL_CONNECTED)
389 | oled.println("N/A");
390 | else
391 | oled.println(WiFi.localIP());
392 | oled.setTextSize(2);
393 | oled.print("CPS:");
394 | oled.print(cps);
395 | oled.setTextSize(1);
396 | if ( cpm < 1000) {
397 | oled.setCursor(67, 16);
398 | }
399 | else {
400 | oled.setCursor(79, 16);
401 | }
402 | oled.print(" A:");
403 | oled.print(uploadcpm);
404 | oled.setCursor(127, 0);
405 | oled.setTextSize(2);
406 | oled.println();
407 | oled.println();
408 | oled.print("CPM:");
409 | if (cpm >= 1) {
410 | oled.println(cpm);
411 | }
412 | oled.setTextSize(1);
413 | oled.print("uSieverts/Hour:");
414 | oled.println(sieverts);
415 | oled.print("mSieverts/Year:");
416 | oled.println(svyear);
417 | if ( cpm < 1000) {
418 | if (cpm >= 110) {
419 | barz = 7;
420 | } else if (cpm < 110 & cpm >= 35) {
421 | barz = 6;
422 | } else if (cpm < 35 & cpm >= 28) {
423 | barz = 5;
424 | } else if (cpm < 28 & cpm >= 23) {
425 | barz = 4;
426 | } else if (cpm < 23 & cpm >= 18) {
427 | barz = 3;
428 | } else if (cpm < 18 & cpm >= 13) {
429 | barz = 2;
430 | } else if (cpm < 13 & cpm >= 9) {
431 | barz = 1;
432 | } else {
433 | barz = 0;
434 | }
435 | for (int b = 0; b <= barz; b++) {
436 | oled.fillRect(90 + (b * 5), 43 - (b * 5), 3, b * 5, WHITE);
437 | }
438 | }
439 | oled.display();
440 | }
441 | void mediumData () { // Geiger data and graph ( max 110 cpm )
442 | oled.clearDisplay();
443 | oled.setCursor(0, 0);
444 | oled.setTextSize(1);
445 | oled.print("uSv/hr:");
446 | oled.print(sieverts);
447 | oled.setCursor(72, 0);
448 | oled.print("Avg:");
449 | oled.println(uploadcpm);
450 | oled.setCursor(0, 16);
451 | oled.setTextSize(1);
452 | oled.print("CPS: ");
453 | oled.setCursor(30, 8);
454 | oled.setTextSize(3);
455 | oled.println(cps);
456 | oled.setTextSize(1);
457 | oled.print("mSv/yr:");
458 | oled.println(svyear);
459 | oled.setTextSize(3);
460 | if (cpm >= 1) {
461 | oled.setCursor(0, 48);
462 | oled.setTextSize(1);
463 | oled.print("CPM: ");
464 | }
465 | oled.setCursor(30, 40);
466 | oled.setTextSize(3);
467 | oled.println(cpm);
468 | if (cpm >= 110) {
469 | barz = 7;
470 | } else if (cpm < 110 & cpm >= 35) {
471 | barz = 6;
472 | } else if (cpm < 35 & cpm >= 28) {
473 | barz = 5;
474 | } else if (cpm < 28 & cpm >= 23) {
475 | barz = 4;
476 | } else if (cpm < 23 & cpm >= 18) {
477 | barz = 3;
478 | } else if (cpm < 18 & cpm >= 13) {
479 | barz = 2;
480 | } else if (cpm < 13 & cpm >= 9) {
481 | barz = 1;
482 | } else {
483 | barz = 0;
484 | }
485 | for (int b = 0; b <= barz; b++) {
486 | oled.fillRect(90 + (b * 5), 35 - (b * 5), 3, b * 5, WHITE);
487 | }
488 | oled.display();
489 | }
490 | void largeData () { // Large count stats and background graph ( max 28 cpm )
491 | if ( cpm >= 1000) {
492 | oled.clearDisplay();
493 | oled.setCursor(0, 0);
494 | oled.setTextSize(4);
495 | if (cpm >= 1) {
496 | oled.print(cps);
497 | }
498 | oled.setTextSize(1);
499 | oled.setCursor(75, 0);
500 | oled.println(timeClient.getFormattedTime());
501 | oled.setCursor(75, 8);
502 | if (statusCode >= 999 )
503 | statusCode = 0;
504 | oled.print("U/L:");
505 | oled.println(statusCode);
506 | oled.setCursor(75, 16);
507 | oled.print("Avg:");
508 | oled.print(uploadcpm);
509 | oled.setCursor(127, 0);
510 | oled.setTextSize(4);
511 | oled.println();
512 | oled.println(cpm);
513 | oled.display();
514 | }
515 | else {
516 | oled.clearDisplay();
517 | oled.setCursor(0, 0);
518 | oled.setTextSize(4);
519 | if (cpm >= 1) {
520 | oled.print(cpm);
521 | }
522 | oled.setTextSize(1);
523 | oled.setCursor(69, 0);
524 | oled.println(timeClient.getFormattedTime());
525 | oled.setCursor(69, 8);
526 | if (statusCode >= 999 )
527 | statusCode = 0;
528 | oled.println(statusCode);
529 | oled.setCursor(69, 16);
530 | oled.print(uploadcpm);
531 | oled.setCursor(127, 0);
532 | oled.setTextSize(4);
533 | oled.println();
534 | oled.println(cps);
535 | if (cpm >= 28) {
536 | barz = 19;
537 | } else if (cpm < 28 & cpm >= 27) {
538 | barz = 18;
539 | } else if (cpm < 27 & cpm >= 26) {
540 | barz = 17;
541 | } else if (cpm < 26 & cpm >= 24) {
542 | barz = 16;
543 | } else if (cpm < 24 & cpm >= 23) {
544 | barz = 15;
545 | } else if (cpm < 23 & cpm >= 22) {
546 | barz = 14;
547 | } else if (cpm < 22 & cpm >= 21) {
548 | barz = 13;
549 | } else if (cpm < 21 & cpm >= 20) {
550 | barz = 12;
551 | } else if (cpm < 20 & cpm >= 19) {
552 | barz = 11;
553 | } else if (cpm < 19 & cpm >= 18) {
554 | barz = 10;
555 | } else if (cpm < 18 & cpm >= 17) {
556 | barz = 9;
557 | } else if (cpm < 17 & cpm >= 16) {
558 | barz = 8;
559 | } else if (cpm < 16 & cpm >= 15) {
560 | barz = 7;
561 | } else if (cpm < 15 & cpm >= 14) {
562 | barz = 6;
563 | } else if (cpm < 14 & cpm >= 13) {
564 | barz = 5;
565 | } else if (cpm < 13 & cpm >= 12) {
566 | barz = 4;
567 | } else if (cpm < 12 & cpm >= 11) {
568 | barz = 3;
569 | } else if (cpm < 11 & cpm >= 10) {
570 | barz = 2;
571 | } else if (cpm < 10 & cpm >= 9) {
572 | barz = 1;
573 | } else {
574 | barz = 0;
575 | }
576 | for (int b = 0; b <= barz; b++) {
577 | oled.fillRect(27 + (b * 5), 60 - (b * 3), 3, b * 3, WHITE);
578 | }
579 | oled.display();
580 | }
581 | }
582 |
583 | void toggleWiFi () { //Toggle WIFI on/off
584 | if (WIFIEnable == 1 )
585 | wifion();
586 | if (WIFIEnable == 0 ) {
587 | wifioff();
588 | stopWiFiAndSleep();
589 | }
590 | oled.clearDisplay();
591 | mode = oldmode;
592 | }
593 | void histogramData () { //Graph Data, autoscale max 16, 32, 64, 128, 256
594 | oled.clearDisplay();
595 | oled.setTextSize(1);
596 | oled.setCursor(36, 0);
597 | // oled.print("mSv/y: ");
598 | oled.println(svyear);
599 | oled.setCursor(80, 0);
600 | oled.println(timeClient.getFormattedTime());
601 | if (recenthi == 14) {
602 | scale = 0.000488281 ;
603 | } else if (recenthi == 13) {
604 | scale = 0.000976562 ;
605 | } else if (recenthi == 12) {
606 | scale = 0.001953125 ;
607 | } else if (recenthi == 11) {
608 | scale = 0.00390625 ;
609 | } else if (recenthi == 10) {
610 | scale = 0.0078125 ;
611 | } else if (recenthi == 9) {
612 | scale = 0.015625 ;
613 | } else if (recenthi == 8) {
614 | scale = 0.03125 ;
615 | } else if (recenthi == 7) {
616 | scale = 0.0625 ;
617 | } else if (recenthi == 6) {
618 | scale = 0.125 ;
619 | } else if (recenthi == 5) {
620 | scale = 0.25 ;
621 | } else if (recenthi == 4) {
622 | scale = 0.5 ;
623 | } else if (recenthi == 3) {
624 | scale = 1 ;
625 | } else if (recenthi == 2) {
626 | scale = 2;
627 | } else if (recenthi == 1) {
628 | scale = 4;
629 | } else if (recenthi == 0) {
630 | scale = 8;
631 | }
632 | for (decltype(xpoints)::index_t i = 0; i <= xpoints.size(); i++) {
633 | oled.fillRect( i + 12 , 65 - (int(scale * xpoints[i])) , 1 , (int(scale * xpoints[i])) , WHITE);
634 | // Serial.print(xpoints[i]);
635 | // Serial.println(int(scale * xpoints[i]));
636 | for (decltype(xpoints)::index_t i = 0; i <= xpoints.size(); i++) {
637 | if (xpoints[i] >= 65537 ) {
638 | recenthi = 14;
639 | scale14 = true;
640 | }
641 | if ( xpoints[i] < 65537 && xpoints[i] >= 32769 && scale14 == false ) {
642 | recenthi = 13;
643 | scale13 = true;
644 | }
645 | if ( xpoints[i] < 32769 && xpoints[i] >= 16385 && scale14 == false && scale13 == false ) {
646 | recenthi = 12;
647 | scale12 = true;
648 | }
649 | if ( xpoints[i] < 16385 && xpoints[i] >= 8193 && scale14 == false && scale13 == false && scale12 == false ) {
650 | recenthi = 11;
651 | scale11 = true;
652 | }
653 | if ( xpoints[i] < 8193 && xpoints[i] >= 4097 && scale14 == false && scale13 == false && scale12 == false && scale11 == false ) {
654 | recenthi = 10;
655 | scale10 = true;
656 | }
657 | if ( xpoints[i] < 4097 && xpoints[i] >= 2049 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false ) {
658 | recenthi = 9;
659 | scale9 = true;
660 | }
661 | if ( xpoints[i] < 2049 && xpoints[i] >= 1025 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false ) {
662 | recenthi = 8;
663 | scale8 = true;
664 | }
665 | if ( xpoints[i] < 1025 && xpoints[i] >= 513 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false ) {
666 | recenthi = 7;
667 | scale7 = true;
668 | }
669 | if ( xpoints[i] < 513 && xpoints[i] >= 257 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false ) {
670 | recenthi = 6;
671 | scale6 = true;
672 | }
673 | if ( xpoints[i] < 257 && xpoints[i] >= 129 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false ) {
674 | recenthi = 5;
675 | scale5 = true;
676 | }
677 | if ( xpoints[i] < 129 && xpoints[i] >= 65 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false ) {
678 | recenthi = 4;
679 | scale4 = true;
680 | }
681 | if ( xpoints[i] < 65 && xpoints[i] >= 33 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false && scale4 == false ) {
682 | recenthi = 3;
683 | scale3 = true;
684 | }
685 | if ( xpoints[i] < 33 && xpoints[i] >= 17 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false && scale4 == false && scale3 == false ) {
686 | recenthi = 2;
687 | scale2 = true;
688 | }
689 | if ( xpoints[i] < 17 && xpoints[i] >= 9 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false && scale4 == false && scale3 == false && scale2 == false ) {
690 | recenthi = 1;
691 | scale1 = true;
692 | }
693 | if ( xpoints[i] < 9 && xpoints[i] >= 1 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false && scale4 == false && scale3 == false && scale2 == false && scale1 == false ) {
694 | recenthi = 0;
695 | scale0 = true;
696 | }
697 | }
698 | oled.setTextColor(WHITE);
699 | oled.setTextSize(1);
700 | oled.setCursor(0, 0);
701 | if ((int(64 / scale) > 1023 )) {
702 | sprintf(buffer, "%dK", int(64 / scale / 1024));
703 | oled.print(buffer);
704 | }
705 | else {
706 | oled.print(int(64 / scale));
707 | }
708 | oled.setCursor(0, 14);
709 | if ((int(48 / scale) == 1536 )) {
710 | oled.print("1.5K");
711 | }
712 | if ((int(48 / scale) > 1536 )) {
713 | sprintf(buffer, "%dK", int(48 / scale / 1024));
714 | oled.print(buffer);
715 | }
716 | if ((int(48 / scale) < 1536 )) {
717 | oled.print(int(48 / scale));
718 | }
719 | oled.setCursor(0, 28);
720 | if ((int(32 / scale) > 1023 )) {
721 | sprintf(buffer, "%dK", int(32 / scale / 1024));
722 | oled.print(buffer);
723 | }
724 | else {
725 | oled.print(int(32 / scale));
726 | }
727 | oled.setCursor(0, 42);
728 | if ((int(16 / scale) > 1023 )) {
729 | sprintf(buffer, "%dK", int(16 / scale / 1024));
730 | oled.print(buffer);
731 | }
732 | else
733 | oled.print(int(16 / scale));
734 | oled.setCursor(0, 57);
735 | oled.print("0");
736 | oled.setTextColor(BLACK);
737 | oled.setCursor(14, 48);
738 | oled.setTextSize(2);
739 | oled.print(cps);
740 | if ( cps < 100 ) {
741 | oled.setTextSize(1);
742 | oled.print("CPS");
743 | }
744 | oled.setCursor(58, 48);
745 | oled.setTextSize(2);
746 | if (xplot >= 1); {
747 | oled.print(xplot);
748 | }
749 | oled.setTextSize(1);
750 | oled.print("CPM");
751 | oled.setCursor(115, 55);
752 | // oled.print("U/L:");
753 | if ((statusCode) == 200) {
754 | oled.print("OK");
755 | }
756 | // else {
757 | // oled.print("NA");
758 | // }
759 | }
760 | scale0 = false;
761 | scale1 = false;
762 | scale2 = false;
763 | scale3 = false;
764 | scale4 = false;
765 | scale5 = false;
766 | scale6 = false;
767 | scale7 = false;
768 | scale8 = false;
769 | scale9 = false;
770 | scale10 = false;
771 | scale11 = false;
772 | scale12 = false;
773 | scale13 = false;
774 | scale14 = false;
775 | oled.setTextColor(WHITE);
776 | oled.display();
777 | }
778 |
779 | void stopWiFiAndSleep() { // Stop and sleep WiFi
780 | WiFi.disconnect();
781 | WiFi.mode(WIFI_OFF);
782 | WiFi.forceSleepBegin();
783 | delay(3);
784 | }
785 | void wifion () { //enable WiFi
786 | sprintf(buffer, "%s\n%s\n", release, releasedate);
787 | Serial.println("");
788 | Serial.println(" ________ __ ____ __");
789 | Serial.println("| | | || |_ .--.--.|_ / .-----. .-----.-----.| |_");
790 | Serial.println("| | | || || | | / /_ | - | _ | | -__|| _|");
791 | Serial.println("|________||__|_||__ ||____||___|_||_||__|__|_____||____|");
792 | Serial.println(" |__| ");
793 |
794 | oled.clearDisplay();
795 | oled.setCursor(0, 0);
796 | oled.setTextSize(1);
797 | Serial.print(buffer);
798 | oled.print(buffer);
799 | battery = oled.getBatteryVoltage();
800 | oled.setBattery(battery);
801 | oled.renderBattery();
802 | oled.println("\n");
803 | APP_NAME = "wifion: ";
804 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
805 | if (WIFIEnable == true) {
806 | sprintf(buffer, "Connecting to\n%s\n", ssid);
807 | oled.print(buffer);
808 | Serial.print(buffer);
809 | oled.display();
810 | WiFi.setHostname(Hostname.c_str());
811 | WiFi.begin(ssid, password);
812 | int retries = 0;
813 | while ((WiFi.status() != WL_CONNECTED) && (retries < 15)) {
814 | retries++;
815 | delay(500);
816 | Serial.print(".");
817 | oled.print(".");
818 | oled.display();
819 | }
820 | }
821 | sprintf(buffer, "\nWiFi status\nIPv4: %s\n", WiFi.localIP().toString().c_str());
822 | Serial.print(buffer);
823 | oled.print(buffer);
824 | oled.display();
825 | delay(1500);
826 | if (WiFi.waitForConnectResult() == WL_CONNECTED) {
827 | MDNS.begin(hostname);
828 | // sprintf(buffer, "WiFi Connected: %s\n", WiFi.localIP().toString().c_str());
829 | timeClient.begin(); // Start NTP client
830 | timeClient.setTimeOffset(3600 * TZ);
831 | timeClient.setUpdateInterval(43200000);
832 | server.on("/", handleRootPath); // activate web servers for diagnostics and upload
833 | server.on("/upload", HTTP_GET, []() {
834 | server.sendHeader("Connection", "close");
835 | server.send(200, "text/html", serverIndex);
836 | });
837 | server.on("/update", HTTP_POST, []() {
838 | server.sendHeader("Connection", "close");
839 | server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
840 | ESP.restart();
841 | }, []() {
842 | HTTPUpload& upload = server.upload();
843 | if (upload.status == UPLOAD_FILE_START) {
844 | Serial.setDebugOutput(true);
845 | WiFiUDP::stopAll();
846 | Serial.printf("Update: %s\n", upload.filename.c_str());
847 | uint32_t maxSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
848 | if (!Update.begin(maxSketchSpace)) { //start with max available size
849 | Update.printError(Serial);
850 | }
851 | } else if (upload.status == UPLOAD_FILE_WRITE) {
852 | if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
853 | Update.printError(Serial);
854 | }
855 | } else if (upload.status == UPLOAD_FILE_END) {
856 | if (Update.end(true)) { //true to set the size to the current progress
857 | Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
858 | } else {
859 | Update.printError(Serial);
860 | }
861 | Serial.setDebugOutput(false);
862 | }
863 | yield();
864 | });
865 | server.begin();
866 | MDNS.addService("http", "tcp", 80);
867 | Serial.printf("Stats available:\n");
868 | Serial.printf("http://%s.local\n", hostname);
869 | Serial.printf("Software upload:\n");
870 | Serial.printf("http://%s.local/upload\n", hostname);
871 | } else {
872 | Serial.println("WiFi Failed");
873 | }
874 |
875 | syslog.log(LOG_INFO, buffer);
876 | oled.clearDisplay();
877 | oled.setCursor(0, 0);
878 | runntp();
879 | }
880 | void wifioff () { // disable WiFi
881 | APP_NAME = "wifioff: ";
882 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
883 | syslog.log(LOG_INFO, "WiFi Disconnect and Powersave");
884 | syslog.log(LOG_INFO, "Will require a reboot to enable radmon.org if enabled");
885 | radmonen = false;
886 | delay(3);
887 | stopWiFiAndSleep();
888 | oled.clearDisplay();
889 | oled.setTextSize(1);
890 | battery = oled.getBatteryVoltage();
891 | oled.setBattery(battery);
892 | oled.renderBattery();
893 | oled.setCursor(0, 0);
894 | sprintf(buffer, "%s\n%s\n\nDisconecting from\n%s\n\nWiFi disconnected\n%s\n\nWifi powersaving on", release, releasedate, ssid, WiFi.localIP().toString().c_str());
895 | oled.print(buffer);
896 | Serial.print(buffer);
897 | oled.display();
898 | delay(2500);
899 | oled.clearDisplay();
900 | }
901 | // Monitor the serial connection from the geiger counter.
902 | // If it is absent for > 15 seconds, display a warning
903 | void serialmon () {
904 | if (millis() > (geigerTimeout + 15000)) {
905 | geigerConnected = false;
906 | geigerconnected = ("false");
907 | oled.clearDisplay();
908 | oled.setTextSize(1);
909 | oled.setCursor(0, 0);
910 | oled.println(Release);
911 | sprintf(buffer, "\nSerial NOT CONNECTED! \nCheck uart connection \nGPIO 13, # 6 on top from L to R");
912 | oled.print(buffer);
913 | oled.display();
914 | APP_NAME = "serialmon: ";
915 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
916 | syslog.log(LOG_INFO, "Geiger not connected! - Check serial port");
917 | geigerTimeout = millis();
918 | delay(3000);
919 | }
920 | }
921 | //***Grab, store and write softSerial data from GPIO 13 to USB serial port*****
922 | void grab() {
923 | if (mySerial.available()) {
924 | geigerdata = (mySerial.read());
925 | geigerSerial += char(geigerdata);
926 | // Serial.write(geigerdata);
927 | delay(1);
928 | }
929 | }
930 | //****Process data****
931 | void process() {
932 | if (geigerdata == 0x0D) { // EOL detected
933 | Log.loop();
934 | geigerConnected = true; // Record that serial connection health is ok
935 | geigerconnected = ("true");
936 | geigerTimeout = millis();
937 | // Parse CPS, CPM, and uS/hr from the string
938 | int comma1Index = geigerSerial.indexOf(',');
939 | int comma2Index = geigerSerial.indexOf(',', comma1Index + 1);
940 | int comma3Index = geigerSerial.indexOf(',', comma2Index + 1);
941 | int comma4Index = geigerSerial.indexOf(',', comma3Index + 1);
942 | int comma5Index = geigerSerial.indexOf(',', comma4Index + 1);
943 | int comma6Index = geigerSerial.indexOf(',', comma5Index + 1);
944 | String cpsString = geigerSerial.substring(comma1Index + 1, comma2Index);
945 | String cpmString = geigerSerial.substring(comma3Index + 1, comma4Index);
946 | String sievertsString = geigerSerial.substring(comma5Index + 1, comma6Index);
947 | cps = cpsString.toInt();
948 | cpm = cpmString.toInt();
949 | sieverts = sievertsString.toFloat();
950 | webdata = geigerSerial;
951 | Log.print(geigerSerial);
952 | svyear = (sieverts * 8.76);
953 | averagedata(); // get data averages
954 | // grabgraphdata(); // grab data for mode 5 graph
955 | geigerSerial = ""; // Clear the string for next time
956 | flashblue (); // Heartbeat pulse
957 | if (cps <= 5)
958 | flashred (); // Flash red LED * CPS
959 | }
960 | }
961 |
962 | // ********Setup*******
963 | void setup() {
964 | pinMode(0, OUTPUT); // setup LEDs
965 | pinMode(2, OUTPUT); // setup LEDs
966 | digitalWrite(2, HIGH); // setup LEDs
967 | digitalWrite(0, HIGH); // setup LEDs
968 | // pinMode(buttonA, INPUT_PULLUP);
969 | // pinMode(buttonB, INPUT_PULLUP);
970 | // pinMode(buttonC, INPUT_PULLUP);
971 | mySerial.begin(9600); // Start software serial link from Gieger
972 | Serial.begin(115200); // Start hardware serial console
973 | while (!Serial)
974 | ; // wait for serial port to connect. Needed for Native USB only
975 | oled.init();
976 | oled.setContrast (contrast); // reduce contrast to preserve OLED display
977 |
978 | // Animate bitmap
979 | for (int i = -1; i <= 10; i++) {
980 | oled.clearDisplay();
981 | oled.drawBitmap(0, (62 - (6 * i)), bootupbitmap, 128, 60, WHITE);
982 | oled.display();
983 | }
984 | delay (1500);
985 |
986 | Log.addPrintStream(std::make_shared(telnetSerialStream));
987 | Log.addPrintStream(std::make_shared(webSerialStream));
988 | wifion(); // Start wifi if enabled
989 | Log.begin();
990 | APP_NAME = "setup: ";
991 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
992 | syslog.log(LOG_INFO, "Initial setup successful");
993 | cpmminavg.begin(); // Init moving average
994 | cpmhouravg.begin(); // Init moving average
995 | timerdelayavg.begin(); // Init moving average
996 | timerdelaydayavg.begin(); // Init moving average
997 | if (randomon == true )
998 | attachInterrupt((pulsepin), grabrandomnum, RISING);
999 | }
1000 |
1001 | // ****Main Loop****
1002 | void loop() {
1003 | serialmon(); // Monitor serial port for disconnection
1004 | grab(); // Grab MightyOhm serial data
1005 | process(); // Extract data and process
1006 | server.handleClient(); // Start Web diagnostics & data server on http://localip:80
1007 | radmon(); // Upload to radmon.org every 60 secs
1008 | logstats(); // Send hourly stats to syslog server
1009 | buttons(); // wait for button input and action
1010 | runntp(); // update NTP if setUpdateInterval in millis has expired
1011 | MDNS.update(); // send mDNS multicast packets if reqd
1012 | grabgraphdata(); // grab data for mode 4 histogram graph
1013 | if (randomon == true ) {
1014 | randomise ();
1015 | echorandom ();
1016 | }
1017 | }
1018 |
--------------------------------------------------------------------------------
/WhyzaGC_4_4_ESP32-release.ino:
--------------------------------------------------------------------------------
1 | // Please use a later release due to issues with this release
2 |
--------------------------------------------------------------------------------
/WhyzaGC_4_7_ESP32_release.ino:
--------------------------------------------------------------------------------
1 | // Please use a later release due to issues with this release
2 |
--------------------------------------------------------------------------------
/WhyzaGC_4_8_ESP32_release.ino:
--------------------------------------------------------------------------------
1 | // Latest version available https://github.com/Whyzanet/WhyzaGC
2 |
3 | const char* release = "WhyzaGC v4.8"; // Version 4 adds MQTT support and a few tidy ups and bugfixes.
4 | const char* releasedate = "Released: 12/5/2024";
5 |
6 | bool WIFIEnable = true; // set startup wifi client behaviour
7 | const char* ssid = "XXXX"; // Set wifi SSID
8 | const char* password = "YYYY"; // Set wifi password
9 | const char* hostname = "WhyzaGC"; // Set own hostname
10 | int TZ = +10; // Set local timezone offset from UTC
11 |
12 | bool radmonen = false; // Set startup radmon.org behaviour. Will enable WIFI if reqd
13 | const char* radmonuser = "XXXX"; // Set radmon.org username
14 | const char* radmonpass = "YYYY"; // Set radmon.org password
15 |
16 | bool NTPEnable = false;
17 | const char* ntpHostname = "pool.ntp.org"; // NTP server hostname. pool.ntp.org
18 |
19 | bool MQTTEnable = false; // set startup mqtt client behaviour
20 | bool MQTT_Use_Hostname = true; // Set to true to use and attempt to resolve via DNS the MQTT broker hostname. Set to false to use IPAddress instead.
21 | const char* mqtthostname = "mqtt.lan"; // mqtt broker hostname.
22 | IPAddress mqtt_serverIP(192, 168, 0, 138); // Optionally set mqtt broker IP if not using hostname.
23 | const char* mqtt_user = "XXXX"; // Set mqtt username
24 | const char* mqtt_password = "YYYY"; // Set mqtt password
25 | const char* mqtt_path = "WhyzaGC/CPM"; // Set mqtt publish path for CPM sensor data
26 | const char* mqtt_id = "WhyzaGC"; // Set mqtt client id
27 |
28 | int contrast = 0; // reduce OLED contrast to preserve OLED lifespan
29 | bool randomon = true; // enable random number generator
30 | int pulsepin = 12;
31 | uint8_t mode = 4; // Startup default OLED display mode - Histogram Display
32 |
33 | #include
34 | #define SYSLOG_SERVER "192.168.0.138" // Set your syslog server.
35 | #define SYSLOG_PORT 514 // Syslog port
36 | #define DEVICE_HOSTNAME "WhyzaGC-ESP32" // Set syslog hostname
37 | const char* APP_NAME = "my-function";
38 | #include
39 | WebServer server(80); // Set web server port
40 | #include
41 | SoftwareSerial mySerial(27, 33); // Gieger serial port directly connected on RX, TX ( no TX connection needed as only receiving data )
42 |
43 | #include
44 | WiFiClient espClient;
45 | PubSubClient mqttclient(espClient);
46 | unsigned long mqtt_delay = 0; // mtqq broker upload sensor data interval
47 | TaskHandle_t Task3;
48 | char mqttbuffer[10];
49 | const char* mqttValue = mqttbuffer;
50 | unsigned long mqtt_online_update_interval = 0; // update the mqtt broker online status at this interval in millis
51 | bool just_reset = 1; // have we just started up after a reset ? If so we will publish radmon status after 60 secs rather than wait for mqtt_online_update_interval
52 | bool MQTT_dns_fail = false; // Set a flag if MQTT DNS lookup is successful
53 |
54 | #include // The T-Logging library.
55 | // Run a telnet service on the default port (23) which shows what is
56 | // sent to Serial if you telnet to it.
57 | //
58 | #include
59 | TelnetSerialStream telnetSerialStream = TelnetSerialStream();
60 | // Likewise let http://:81/ show the log in a webbrowser.
61 | //
62 | #include
63 | WebSerialStream webSerialStream = WebSerialStream(81);
64 |
65 | #include
66 | #include
67 | const char* serverIndex = "";
68 | #include
69 | #include
70 | #include // we need to do some averaging
71 | #include
72 | #include
73 | #include
74 | #include
75 | #include
76 | #include
77 | #include
78 | #include
79 | #include "uptime_formatter.h"
80 | #include // Histogram data
81 | #define buttonA 15
82 | #define buttonB 32
83 | #define buttonC 14
84 | Adafruit_FeatherOLED_SH110X oled = Adafruit_FeatherOLED_SH110X();
85 | WiFiUDP ntpUDP;
86 | NTPClient timeClient(ntpUDP, ntpHostname);
87 | WiFiUDP udpClient;
88 | IPAddress ip;
89 | bool NTP_dns = false; // Set a flag if NTP DNS lookup is successful
90 | movingAvg cpmminavg(60); // keep a 1 minute moving average of CPM data to upload
91 | movingAvg cpmhouravg(3600);
92 | movingAvg timerdelayavg(60);
93 | movingAvg timerdelaydayavg(1440);
94 | CircularBuffer xpoints; // mode 5 histogram graph data
95 | unsigned long uploadcpm = 0;
96 | unsigned long cpmhour = 0;
97 | unsigned long uploaddelay = 0; // measure the radmon upload time.
98 | unsigned long lastupdate = 0;
99 | unsigned long avgdelay = 0;
100 | unsigned long logdelay = 0;
101 | unsigned long timeravg = 0;
102 | unsigned long timerdayavg = 0;
103 | unsigned long buttontimer = 0;
104 | String Release = release;
105 | String ReleaseDate = releasedate;
106 | String Hostname = hostname;
107 | int statusCode = 0;
108 | uint8_t oldmode;
109 | bool geigerConnected = false;
110 | bool radmon_fail = false;
111 | bool radmon_fail_alert = false;
112 | String geigerconnected;
113 | unsigned long geigerTimeout = 0;
114 | bool gotButton = false;
115 | String geigerSerial;
116 | unsigned char geigerdata;
117 | String webdata;
118 | String response;
119 | int barz = 0;
120 | int cps = 0;
121 | int cpm = 0;
122 | int xsize = 0;
123 | int xplot = 0;
124 | float sieverts = 0;
125 | float svyear = 0;
126 | float battery = oled.getBatteryVoltage();
127 | char buffer[255];
128 | unsigned long timer = 0;
129 | unsigned long timertotal = 0;
130 | float scale = 0; // Setup histogram variables
131 | int recenthi = 0;
132 | int previoushi = 0;
133 | bool scale0 = false;
134 | bool scale1 = false;
135 | bool scale2 = false;
136 | bool scale3 = false;
137 | bool scale4 = false;
138 | bool scale5 = false;
139 | bool scale6 = false;
140 | bool scale7 = false;
141 | bool scale8 = false;
142 | bool scale9 = false;
143 | bool scale10 = false;
144 | bool scale11 = false;
145 | bool scale12 = false;
146 | bool scale13 = false;
147 | bool scale14 = false;
148 | unsigned long grabgraphdatadelay = 0;
149 | int randomresult = -1;
150 | int gotrandomresult = 0x00;
151 | #define PIN 0 //NeoPixel
152 | #define NUMPIXELS 1
153 | Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
154 | #define COMMON_ANODE
155 | TaskHandle_t Task1;
156 | TaskHandle_t Task2;
157 | bool newrandom = false;
158 |
159 |
160 | void ardota() {
161 | // Port defaults to 3232
162 | // ArduinoOTA.setPort(3232);
163 |
164 | // Hostname defaults to esp3232-[MAC]
165 | ArduinoOTA.setHostname("WhyzaGC-ESP32");
166 |
167 | // No authentication by default
168 | // ArduinoOTA.setPassword("admin");
169 |
170 | // Password can be set with it's md5 value as well
171 | // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
172 | // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
173 |
174 | ArduinoOTA
175 | .onStart([]() {
176 | String type;
177 | if (ArduinoOTA.getCommand() == U_FLASH)
178 | type = "sketch";
179 | else // U_SPIFFS
180 | type = "filesystem";
181 |
182 | // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
183 | // Serial.println("Start updating " + type);
184 | Log.println("Start updating " + type);
185 | })
186 | .onEnd([]() {
187 | // Serial.println("\nEnd");
188 | Log.println("\nEnd");
189 | })
190 | .onProgress([](unsigned int progress, unsigned int total) {
191 | // Serial.printf("Progress: %u%%\n\r", (progress / (total / 100)));
192 | Log.printf("Progress: %u%%\n\r", (progress / (total / 100)));
193 | })
194 | .onError([](ota_error_t error) {
195 | // Serial.printf("Error[%u]: ", error);
196 | Log.printf("Error[%u]: ", error);
197 | // if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
198 | // else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
199 | // else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
200 | // else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
201 | // else if (error == OTA_END_ERROR) Serial.println("End Failed");
202 | if (error == OTA_AUTH_ERROR) Log.println("Auth Failed");
203 | else if (error == OTA_BEGIN_ERROR) Log.println("Begin Failed");
204 | else if (error == OTA_CONNECT_ERROR) Log.println("Connect Failed");
205 | else if (error == OTA_RECEIVE_ERROR) Log.println("Receive Failed");
206 | else if (error == OTA_END_ERROR) Log.println("End Failed");
207 | });
208 |
209 | ArduinoOTA.begin();
210 | }
211 |
212 | void mqttpub(void* ptParameters) { // publish CPM data and status to MQTT broker using 2nd CPU
213 | for (;;) {
214 | APP_NAME = "mqttpub:";
215 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
216 | if ((MQTTEnable == 1) && (geigerConnected == true) && (MQTT_dns_fail == 0)) {
217 | if (WIFIEnable == 0 || WiFi.status() != WL_CONNECTED) {
218 | statusCode = 0;
219 | }
220 | if (WIFIEnable == 1 && (millis() > (mqtt_delay + 60000))) {
221 | if (WiFi.status() != WL_CONNECTED) {
222 | wifion();
223 | } else {
224 | while (!mqttclient.connected()) {
225 | // Log.print("Attempting MQTT connection...");
226 | if (mqttclient.connect(mqtt_id, mqtt_user, mqtt_password)) {
227 | // Log.println("MQTT connected");
228 | APP_NAME = "mqttpub:";
229 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
230 | // syslog.log(LOG_INFO, "Init MQTT connection");
231 | // String logMessage = String(mqtthostname) + " > " + ip.toString();
232 | // syslog.log(LOG_INFO, logMessage.c_str());
233 | ltoa(uploadcpm, mqttbuffer, 10); // Convert the value to a string
234 | mqttValue = mqttbuffer; // Assign the converted string to a const char*
235 | mqttclient.publish(mqtt_path, mqttValue);
236 | // Log.print("sieverts: ");
237 | // Log.println(sieverts);
238 | char buffer[10]; // Buffer to store the converted value
239 | dtostrf(sieverts, 4, 2, buffer); // Convert float to const char*
240 | const char* sievertsChar = buffer; // Assign buffer to const char*
241 | mqttclient.publish("WhyzaGC/sieverts", sievertsChar);
242 | if (millis() > mqtt_online_update_interval + 300000) {
243 | mqttclient.publish("WhyzaGC/status", "online");
244 | if (radmon_fail == 0) {
245 | mqttclient.publish("WhyzaGC/radmon_status", "online");
246 | }
247 | mqtt_online_update_interval = millis();
248 | } else if (just_reset == 1 && radmon_fail == 0) {
249 | mqttclient.publish("WhyzaGC/radmon_status", "online");
250 | just_reset = 0;
251 | }
252 | if (radmon_fail == 1 && radmon_fail_alert == 0) {
253 | mqttclient.publish("WhyzaGC/radmon_status", "Alert - Unable to connect to radmon.org");
254 | radmon_fail_alert = true;
255 | }
256 | if (radmon_fail == 0 && radmon_fail_alert == 1) {
257 | mqttclient.publish("WhyzaGC/radmon_status", "Connection to radmon.org restablished ;)");
258 | radmon_fail_alert = false;
259 | }
260 | // Log.println("Published");
261 | } else {
262 | // Log.print("MQTT failed, rc=");
263 | // Log.print(mqttclient.state());
264 | // syslog.log(LOG_INFO, "MQTT upload failed");
265 | // String logMessage = String(mqttclient.state());
266 | // syslog.log(LOG_INFO, logMessage.c_str());
267 | }
268 | }
269 | }
270 | mqtt_delay = millis();
271 | }
272 | }
273 | delay(1000);
274 | }
275 | }
276 |
277 | // replace with your own logo via http://javl.github.io/image2cpp/. Ensure it is 128 x 64 pixels
278 |
279 | const unsigned char bootupbitmap[] PROGMEM = {
280 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
281 | 0x00, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
282 | 0x00, 0x00, 0x07, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
283 | 0x00, 0x00, 0x1f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
284 | 0x00, 0x00, 0x7f, 0x00, 0x07, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285 | 0x00, 0x01, 0xf8, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
286 | 0x00, 0x07, 0xe0, 0x7f, 0xe0, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
287 | 0x00, 0x0f, 0x83, 0xff, 0xfe, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
288 | 0x00, 0x1e, 0x1f, 0xff, 0xff, 0x87, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
289 | 0x00, 0x3c, 0x1f, 0xff, 0xff, 0xc1, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
290 | 0x00, 0x78, 0x1f, 0xff, 0xff, 0x80, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
291 | 0x00, 0xf0, 0x0f, 0xff, 0xff, 0x80, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
292 | 0x01, 0xe0, 0x0f, 0xff, 0xff, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 | 0x01, 0xc0, 0x07, 0xff, 0xff, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
294 | 0x03, 0x80, 0x03, 0xff, 0xfe, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
295 | 0x07, 0x00, 0x03, 0xff, 0xfc, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
296 | 0x07, 0x00, 0x01, 0xff, 0xfc, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
297 | 0x0e, 0x00, 0x01, 0xff, 0xf8, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
298 | 0x0e, 0x00, 0x00, 0xff, 0xf8, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
299 | 0x1c, 0x00, 0x00, 0xff, 0xf0, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
300 | 0x1c, 0x00, 0x00, 0x7f, 0xf0, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
301 | 0x18, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
302 | 0x38, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x01, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
303 | 0x38, 0x00, 0x00, 0x10, 0x40, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
304 | 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 | 0x30, 0x00, 0x00, 0x0f, 0x80, 0x00, 0x00, 0xe0, 0x00, 0x03, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00,
306 | 0x30, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x00, 0xe0, 0xe7, 0x3b, 0x80, 0x00, 0x00, 0x01, 0xfc, 0x7f,
307 | 0x30, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x00, 0xe0, 0xe7, 0xbb, 0x80, 0x00, 0x00, 0x03, 0xfc, 0xff,
308 | 0x70, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0xe0, 0xff, 0xbb, 0xfb, 0x9f, 0xfb, 0xf7, 0x81, 0xe0,
309 | 0x70, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x60, 0x7f, 0xfb, 0xfb, 0xbc, 0x78, 0xf7, 0x81, 0xe0,
310 | 0x73, 0xff, 0xfe, 0x7f, 0xe7, 0xff, 0xfc, 0x60, 0x7f, 0xf3, 0xbb, 0xf8, 0xf8, 0x3f, 0x3d, 0xc0,
311 | 0x73, 0xff, 0xff, 0x7f, 0xe7, 0xff, 0xfc, 0xe0, 0x7d, 0xf3, 0xb9, 0xf9, 0xf7, 0xff, 0x9d, 0xe0,
312 | 0x33, 0xff, 0xff, 0x3f, 0xe7, 0xff, 0xfc, 0xe0, 0x7d, 0xf3, 0xb9, 0xfb, 0xe7, 0xff, 0x9d, 0xe0,
313 | 0x31, 0xff, 0xff, 0x1f, 0xcf, 0xff, 0xfc, 0xe0, 0x3d, 0xf3, 0xb8, 0xf3, 0xc7, 0xfb, 0xfc, 0xff,
314 | 0x31, 0xff, 0xff, 0x8f, 0x8f, 0xff, 0xfc, 0xe0, 0x3c, 0xe3, 0xb8, 0xf3, 0xff, 0xf9, 0xfc, 0x7f,
315 | 0x39, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xfc, 0xe0, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00,
316 | 0x39, 0xff, 0xff, 0xc0, 0x3f, 0xff, 0xf8, 0xc0, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00,
317 | 0x39, 0xff, 0xff, 0xc0, 0x1f, 0xff, 0xf9, 0xc0, 0x00, 0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00,
318 | 0x18, 0xff, 0xff, 0x80, 0x1f, 0xff, 0xf9, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
319 | 0x1c, 0xff, 0xff, 0x80, 0x0f, 0xff, 0xf1, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
320 | 0x1c, 0x7f, 0xff, 0x00, 0x07, 0xff, 0xf3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
321 | 0x0e, 0x7f, 0xfe, 0x00, 0x07, 0xff, 0xe3, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
322 | 0x0e, 0x3f, 0xfe, 0x00, 0x03, 0xff, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
323 | 0x07, 0x3f, 0xfc, 0x00, 0x03, 0xff, 0xc7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
324 | 0x07, 0x1f, 0xfc, 0x00, 0x01, 0xff, 0x8e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
325 | 0x03, 0x8f, 0xf8, 0x00, 0x01, 0xff, 0x9e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
326 | 0x01, 0xc7, 0xf8, 0x00, 0x00, 0xff, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327 | 0x01, 0xe3, 0xf0, 0x00, 0x00, 0x7e, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
328 | 0x00, 0xf1, 0xe0, 0x00, 0x00, 0x7c, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
329 | 0x00, 0x78, 0xe0, 0x00, 0x00, 0x30, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
330 | 0x00, 0x3c, 0x00, 0x00, 0x00, 0x21, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
331 | 0x00, 0x1e, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
332 | 0x00, 0x0f, 0x80, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
333 | 0x00, 0x07, 0xe0, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
334 | 0x00, 0x01, 0xf8, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
335 | 0x00, 0x00, 0x7f, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
336 | 0x00, 0x00, 0x1f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
337 | 0x00, 0x00, 0x07, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
338 | 0x00, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
339 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
340 | };
341 |
342 | //***Functions***
343 |
344 |
345 | void IRAM_ATTR grabrandomnum() {
346 | detachInterrupt(pulsepin);
347 | newrandom = true;
348 | gotrandomresult = (randomresult);
349 | // while (digitalRead(pulsepin) == 0);
350 | attachInterrupt(digitalPinToInterrupt(pulsepin), grabrandomnum, RISING);
351 | }
352 |
353 | void randomise(void* ptParameters) {
354 | for (;;) {
355 | if (randomresult == 0xF) {
356 | randomresult = 0;
357 | delay(1);
358 | } else {
359 | randomresult = (randomresult + 1);
360 | delay(1);
361 | }
362 | }
363 | }
364 |
365 | void echorandom() {
366 | if (newrandom == true) {
367 | Log.println("");
368 | Log.printf("%01x", gotrandomresult);
369 | newrandom = false;
370 | }
371 | }
372 |
373 | void stopWiFiAndSleep() { // Stop sleep
374 | WiFi.disconnect(true);
375 | WiFi.mode(WIFI_OFF);
376 | delay(3);
377 | }
378 | void wifion() { //enable WiFi
379 | sprintf(buffer, "%s\n%s\n", release, releasedate);
380 | Serial.println("");
381 | Serial.println(" ________ __ ____ __");
382 | Serial.println("| | | || |_ .--.--.|_ / .-----. .-----.-----.| |_");
383 | Serial.println("| | | || || | | / /_ | - | _ | | -__|| _|");
384 | Serial.println("|________||__|_||__ ||____||___|_||_||__|__|_____||____|");
385 | Serial.println(" |__| ");
386 |
387 | oled.clearDisplay();
388 | oled.setCursor(0, 0);
389 | oled.setTextSize(1);
390 | Serial.print(buffer);
391 | oled.print(buffer);
392 | battery = oled.getBatteryVoltage();
393 | oled.setBattery(battery);
394 | oled.renderBattery();
395 | oled.println("\n");
396 | APP_NAME = "wifion:";
397 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
398 | if (WIFIEnable == true) {
399 | sprintf(buffer, "Connecting to\n%s\n", ssid);
400 | oled.print(buffer);
401 | Serial.print(buffer);
402 | oled.display();
403 | // WiFiClient setTimeout(10000);
404 | WiFi.setHostname(Hostname.c_str());
405 | WiFi.begin(ssid, password);
406 | int retries = 0;
407 | while ((WiFi.status() != WL_CONNECTED) && (retries < 15)) {
408 | retries++;
409 | delay(500);
410 | Serial.print(".");
411 | oled.print(".");
412 | oled.display();
413 | }
414 | }
415 | sprintf(buffer, "\nWiFi status\nIPv4: %s\n", WiFi.localIP().toString().c_str());
416 | Serial.print(buffer);
417 | oled.print(buffer);
418 | oled.display();
419 | delay(1500);
420 | if (WiFi.waitForConnectResult() == WL_CONNECTED) {
421 | MDNS.begin(hostname);
422 | MDNS.addService("http", "tcp", 80);
423 |
424 | Serial.printf("Stats available:\n");
425 | Serial.printf("http://%s.local\n", hostname);
426 | Serial.printf("Software upload:\n");
427 | Serial.printf("http://%s.local/upload\n", hostname);
428 | } else {
429 | Serial.println("WiFi Failed");
430 | }
431 | oled.clearDisplay();
432 | oled.setCursor(0, 0);
433 |
434 | String ipAddress = "Assigned WiFi IP Address: " + WiFi.localIP().toString();
435 | // Print IP address to syslog
436 | syslog.log(LOG_INFO, ipAddress.c_str());
437 | }
438 | void wifioff() { // disable WiFi
439 | APP_NAME = "wifioff:";
440 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
441 | syslog.log(LOG_INFO, "WiFi Disconnect and Powersave");
442 | syslog.log(LOG_INFO, "Will require a reboot to enable radmon.org if enabled");
443 | radmonen = false;
444 | delay(3);
445 | stopWiFiAndSleep();
446 | oled.clearDisplay();
447 | oled.setTextSize(1);
448 | battery = oled.getBatteryVoltage();
449 | oled.setBattery(battery);
450 | oled.renderBattery();
451 | oled.setCursor(0, 0);
452 | sprintf(buffer, "%s\n%s\n\nDisconecting from\n%s\n\nWiFi disconnected\n%s\n\nWifi powersaving on", release, releasedate, ssid, WiFi.localIP().toString().c_str());
453 | oled.print(buffer);
454 | Serial.print(buffer);
455 | oled.display();
456 | delay(2500);
457 | oled.clearDisplay();
458 | }
459 |
460 | void ntpsetup() {
461 | APP_NAME = "ntpsetup:";
462 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
463 | if (NTPEnable == 1) {
464 | if (WiFi.hostByName(ntpHostname, ip)) {
465 | Log.print("Resolved NTP server hostname successfully: ");
466 | syslog.log(LOG_INFO, "Resolved NTP server hostname successfully");
467 | Log.print(ntpHostname);
468 | // syslog.log(LOG_INFO, ntpHostname);
469 | Log.print(": ");
470 | Log.println(ip);
471 | // syslog.log(LOG_INFO, ip.toString());
472 | String logMessage = String(ntpHostname) + " > " + ip.toString();
473 | syslog.log(LOG_INFO, logMessage.c_str());
474 |
475 | NTPClient timeClient(ntpUDP, ip);
476 | timeClient.setTimeOffset(3600 * TZ);
477 | timeClient.setUpdateInterval(3600000);
478 | timeClient.begin(); // Start NTP client
479 | syslog.log(LOG_INFO, "Using configured NTP DNS name IP address: ");
480 | syslog.log(LOG_INFO, ip.toString());
481 | NTP_dns = true;
482 | } else {
483 | syslog.log(LOG_INFO, "NTP hostname failed to resolve.");
484 | }
485 | } else {
486 | syslog.log(LOG_INFO, "NTP is set to disable");
487 | }
488 | }
489 |
490 | void httpdsetup() {
491 | APP_NAME = "httpdsetup:";
492 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
493 | syslog.log(LOG_INFO, "Started HTTP server");
494 | server.on("/", handleRootPath); // Setup web servers for root and upload
495 | server.on("/upload", HTTP_GET, []() {
496 | server.sendHeader("Connection", "close");
497 | server.send(200, "text/html", serverIndex);
498 | });
499 | server.on(
500 | "/update", HTTP_POST, []() {
501 | server.sendHeader("Connection", "close");
502 | server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
503 | ESP.restart();
504 | },
505 | []() {
506 | HTTPUpload& upload = server.upload();
507 | if (upload.status == UPLOAD_FILE_START) {
508 | Serial.printf("Update: %s\n", upload.filename.c_str());
509 | if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
510 | Update.printError(Serial);
511 | }
512 | } else if (upload.status == UPLOAD_FILE_WRITE) {
513 | /* flashing firmware to ESP*/
514 | if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
515 | Update.printError(Serial);
516 | }
517 | } else if (upload.status == UPLOAD_FILE_END) {
518 | if (Update.end(true)) { //true to set the size to the current progress
519 | Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
520 | } else {
521 | Update.printError(Serial);
522 | }
523 | Serial.setDebugOutput(false);
524 | }
525 | });
526 | server.begin();
527 | }
528 |
529 | void mqttsetup() {
530 | APP_NAME = "mqttsetup:";
531 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
532 | if (MQTTEnable == 1 && (MQTT_Use_Hostname == 1)) {
533 | IPAddress ip;
534 | if (WiFi.hostByName(mqtthostname, ip)) {
535 | Log.print("Resolved MQTT broker hostname successfully: ");
536 | syslog.log(LOG_INFO, "Resolved MQTT broker hostname successfully");
537 | Log.print(mqtthostname);
538 | // syslog.log(LOG_INFO, mqtthostname);
539 | Log.print(": ");
540 | Log.println(ip);
541 | // syslog.log(LOG_INFO, ip.toString());
542 | String logMessage = String(mqtthostname) + " > " + ip.toString();
543 | syslog.log(LOG_INFO, logMessage.c_str());
544 | mqttclient.setServer(ip, 1883); // Use the resolved IP when specifying a valid mqtt hostname
545 | } else {
546 | Log.print("Failed to resolve MQTT server IP address for ");
547 | syslog.log(LOG_INFO, "Failed to resolve MQTT IP address for ");
548 | Log.println(mqtthostname);
549 | syslog.log(LOG_INFO, mqtthostname);
550 | syslog.log(LOG_INFO, "***Disabling MQTT support***");
551 | MQTT_dns_fail = true;
552 | }
553 | // mqttclient.setServer(ip, 1883); // Use when specifying mqtt hostname
554 | } else {
555 | if (MQTTEnable == 1 && (MQTT_Use_Hostname == 0)) {
556 | mqttclient.setServer(mqtt_serverIP, 1883); // Use when specifying mqtt IP address
557 | syslog.log(LOG_INFO, "Using configured MQTT broker IP address: ");
558 | syslog.log(LOG_INFO, mqtt_serverIP.toString());
559 | }
560 | }
561 | if (mqttclient.connect(mqtt_id, mqtt_user, mqtt_password)) {
562 | mqttclient.publish("WhyzaGC/status", "online");
563 | } else {
564 | if (MQTTEnable == 1) {
565 | syslog.log(LOG_INFO, "***MQTT upload failed***");
566 | // String logMessage = String(mqttclient.state());
567 | // syslog.log(LOG_INFO, logMessage.c_str());
568 | }
569 | }
570 | }
571 |
572 | void grabgraphdata() { // grab histogram graph data for mode 5 display
573 | if (millis() > (grabgraphdatadelay + 1000)) {
574 | // if (cpm >= 1) {
575 | xpoints.push(cpm);
576 | xsize = xpoints.size();
577 | xplot = xpoints.last();
578 |
579 | // for (decltype(xpoints)::index_t i = 0; i < xpoints.size(); i++) {
580 | // Serial.print(xpoints[i]);
581 | // }
582 | // Serial.println(" ");
583 | grabgraphdatadelay = millis();
584 | }
585 | }
586 | String stripCommas(const String& str) {
587 | String result = str;
588 | result.replace(',', ' '); // Remove commas from the Uptime String, it confuses syslog
589 | return result;
590 | }
591 | void logstats() { // remote syslog status
592 | if (millis() > (logdelay + 3600000)) {
593 | APP_NAME = "logstats:";
594 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
595 | syslog.logf(LOG_INFO, "1 min average CPM: %d", uploadcpm);
596 | syslog.logf(LOG_INFO, "1 hour average CPM: %d", cpmhour);
597 | syslog.logf(LOG_INFO, "HTTP response: %d", statusCode);
598 | String uptimeString = uptime_formatter::getUptime();
599 | String modifiedUptimeString = stripCommas(uptimeString);
600 | syslog.logf(LOG_INFO, "Uptime: %s", modifiedUptimeString.c_str());
601 | logdelay = millis();
602 | }
603 | }
604 |
605 | void averagedata() { // calculate CPM data average for radmon upload
606 | if (millis() > (avgdelay + 550)) {
607 | uploadcpm = cpmminavg.reading(cpm);
608 | cpmhour = cpmhouravg.reading(cpm);
609 | avgdelay = millis();
610 | }
611 | }
612 |
613 | void radmon(void* ptParameters) { // perfrom the HTTP Get for radmon.org every minute
614 | APP_NAME = "radmon:";
615 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
616 | for (;;) {
617 | if (radmonen == 1 && (geigerConnected == true)) {
618 | if (WIFIEnable == 0 || WiFi.status() != WL_CONNECTED) {
619 | statusCode = 0;
620 | }
621 | if (WIFIEnable == 1 && (millis() > (uploaddelay + 59999 - timertotal))) {
622 | if (WiFi.status() != WL_CONNECTED) {
623 | wifion();
624 | } else {
625 | pixels.clear();
626 | pixels.setPixelColor(0, pixels.Color(255, 0, 255)); // flash neopixel purple when starting http client upload
627 | pixels.show();
628 | delay(80);
629 | pixels.clear();
630 | pixels.show();
631 | delay(80);
632 | pixels.setPixelColor(0, pixels.Color(255, 0, 255));
633 | pixels.show();
634 | delay(80);
635 | pixels.clear();
636 | pixels.show();
637 | String ptr = "/radmon.php?function=submit";
638 | ptr += "&user=";
639 | ptr += radmonuser;
640 | ptr += "&password=";
641 | ptr += radmonpass;
642 | ptr += "&value=";
643 | ptr += uploadcpm;
644 | ptr += "&unit=CPM";
645 | timer = (millis());
646 | WiFiClient wifi;
647 | HttpClient client = HttpClient(wifi, "www.radmon.org", 80);
648 | client.get(ptr);
649 | statusCode = client.responseStatusCode();
650 | response = client.responseBody();
651 | lastupdate = uploadcpm;
652 | uploaddelay = millis();
653 | timertotal = (millis() - timer);
654 | // Log.println(timertotal);
655 | timeravg = timerdelayavg.reading(timertotal);
656 | timerdayavg = timerdelaydayavg.reading(timertotal);
657 | if (statusCode == 200) {
658 | flashgreen(); // successful update
659 | if (response != "OK
") {
660 | syslog.logf(LOG_INFO, "Alert - HTTP/Get response body: %s", response);
661 | // Log.println(response); // if you are seeing "Too soon" logged from radmon, ensure updates are greater than 30 secs apart.
662 | }
663 | if (radmon_fail == 1) {
664 | syslog.log(LOG_INFO, "HTTP/Get response code: OK");
665 | // Log.print("Connection to radmon.org restablished ;)");
666 | radmon_fail = false;
667 | }
668 | } else {
669 | flashalertred(); // unsuccessful update
670 | if (radmon_fail == false) {
671 | syslog.log(LOG_INFO, "Alert - No response to TCP SYN or HTTP/Get != OK");
672 | syslog.logf(LOG_INFO, "HTTP/Get response code: %d", statusCode);
673 | syslog.logf(LOG_INFO, "HTTP/Get response body: %s", response);
674 | // Log.print("Alert - Unable to connect to radmon.org");
675 | }
676 | radmon_fail = true;
677 | }
678 | // Log.println(timeravg);
679 | // Log.print("radmon uploaded using core ");
680 | // Log.println(xPortGetCoreID());
681 | }
682 | }
683 | }
684 | delay(1000);
685 | }
686 | }
687 |
688 | void runntp() {
689 | if ((NTPEnable == 1) && (NTP_dns == 1)) {
690 | timeClient.setTimeOffset(3600 * TZ);
691 | timeClient.setUpdateInterval(3600000);
692 | timeClient.update();
693 | //Serial.println(timeClient.getFormattedTime());
694 | //Serial.println(timeClient.getFormattedDate());
695 | }
696 | }
697 |
698 | void flashgreen() { // radmon update successful
699 | pixels.clear();
700 | pixels.setPixelColor(0, pixels.Color(0, 255, 0));
701 | pixels.show();
702 | delay(80);
703 | pixels.clear();
704 | pixels.show();
705 | delay(80);
706 | pixels.setPixelColor(0, pixels.Color(0, 255, 0));
707 | pixels.show();
708 | delay(80);
709 | pixels.clear();
710 | pixels.show();
711 | delay(80);
712 | pixels.setPixelColor(0, pixels.Color(0, 255, 0));
713 | pixels.show();
714 | delay(80);
715 | pixels.clear();
716 | pixels.show();
717 | }
718 | void flashalertred() { // radmon update failed
719 | pixels.clear();
720 | pixels.setPixelColor(0, pixels.Color(255, 0, 0));
721 | pixels.show();
722 | delay(80);
723 | pixels.clear();
724 | pixels.show();
725 | delay(80);
726 | pixels.setPixelColor(0, pixels.Color(255, 0, 0));
727 | pixels.show();
728 | delay(80);
729 | pixels.clear();
730 | pixels.show();
731 | delay(80);
732 | pixels.setPixelColor(0, pixels.Color(255, 0, 0));
733 | pixels.show();
734 | delay(80);
735 | pixels.clear();
736 | pixels.show();
737 | }
738 | void flashblue() { // flash blue NeoPixel HeartBeat for every serial EOL received ( should be 1 sec )
739 | pixels.clear();
740 | pixels.setPixelColor(0, pixels.Color(0, 0, 255));
741 | pixels.show();
742 | delay(80);
743 | pixels.clear();
744 | pixels.show();
745 | }
746 | void flashred() { // flash red LED CPS times
747 | for (int i = 1; i <= cps; i++) {
748 | digitalWrite(13, HIGH); // Flash red LED * cps
749 | delay(40);
750 | digitalWrite(13, LOW);
751 | delay(40);
752 | }
753 | }
754 | void handleRootPath() { // Web diagnostics page
755 | server.send(200, "text/plain", Release + ("\n") + (ReleaseDate) + ("\n") + ("Hardware: Feather Huzzah ESP32 v2") + ("\n") + ("\n") + (" ________ __ ____ __") + ("\n") + ("| | | || |_ .--.--.|_ / .-----. .-----.-----.| |_") + ("\n") + ("| | | || || | | / /_ | - | _ | | -__|| _|") + ("\n") + ("|________||__|_||__ ||____||___|_||_||__|__|_____||____|") + ("\n") + (" |__| ") + ("\n") + ("\n") + (timeClient.getFormattedTime()) + ("\n") + ("Uptime: ") + (uptime_formatter::getUptime()) + ("\n") + ("\n") + ("Geiger Connected: ") + geigerconnected + (" ") + ("\n") + ("\n") + ("Rolling Average CPM: ") + uploadcpm + ("\n") + ("Rolling 1 hour Average CPM: ") + cpmhour + ("\n") + ("\n") + ("uSieverts/Hour: ") + sieverts + ("\n") + ("mSieverts/Year: ") + svyear + ("\n") + ("\n") + ("Last Radmon Update(secs): ") + ((millis() - uploaddelay) / 1000) + ("\n") + ("Radmon HTTP Get status code: ") + statusCode + ("\n") + ("Radmon HTTP Get response body: ") + response + ("\n") + ("Last Upload Delay(ms): ") + timertotal + ("\n") + ("Rolling 1 hour Average Upload Delay(ms): ") + timeravg + ("\n") + ("Rolling 1 day Average Upload Delay(ms): ") + timerdayavg + ("\n") + ("Last Radmon Update CPM: ") + lastupdate + ("\n\n") + ("Current Data:") + webdata + ("\n\n") + ("Debug:\n") + ("Scale: ") + scale + (" recenthi: ") + recenthi + (" xplot: ") + xplot + ("\n"));
756 | }
757 |
758 | void buttons() { // check for button presses
759 | if (millis() > (buttontimer + 500)) {
760 | buttontimer = millis();
761 | if (!digitalRead(buttonC) && (!digitalRead(buttonB))) { // Check if a button is pressed and change mode accordingly
762 | oldmode = mode;
763 | WIFIEnable = !WIFIEnable;
764 | mode = 5;
765 | gotButton = true;
766 | } else if (!digitalRead(buttonA)) {
767 | mode = (mode + 1);
768 | if (mode == 4 | mode == 5)
769 | mode = 1;
770 | gotButton = true;
771 | } else if (!digitalRead(buttonB)) {
772 | mode = 4;
773 | gotButton = true;
774 | } else if (!digitalRead(buttonC)) {
775 | mode = (mode - 1);
776 | if (mode == 0) {
777 | mode = 3;
778 | }
779 | gotButton = true;
780 | }
781 |
782 | if (gotButton)
783 | delay(25); // Debounce
784 | switch (mode) { // Display current mode
785 | case 1: // All data and graph ( max 110 cpm )
786 | smallData();
787 | break;
788 | case 2: // Geiger data and graph ( max 110 cpm )
789 | mediumData();
790 | break;
791 | case 3: // Large count stats and background graph ( max 28 cpm )
792 | largeData();
793 | break;
794 | case 5: //Toggle WIFI on/off - Buttons B&C
795 | toggleWiFi();
796 | break;
797 | case 4: //Graph Data, autoscale max 16, 32, 64, 128, 256
798 | histogramData();
799 | break;
800 | }
801 | }
802 | }
803 | void smallData() { // All data and graph ( max 110 cpm )
804 | oled.clearDisplay();
805 | oled.setCursor(0, 0);
806 | oled.setTextSize(1);
807 | oled.print("HTTP Get:");
808 | if (statusCode >= 999)
809 | statusCode = 0;
810 | oled.print(statusCode);
811 | oled.setCursor(80, 0);
812 | oled.println(timeClient.getFormattedTime());
813 | oled.print("WiFi:");
814 | if (WiFi.status() != WL_CONNECTED)
815 | oled.println("N/A");
816 | else
817 | oled.println(WiFi.localIP());
818 | oled.setTextSize(2);
819 | oled.print("CPS:");
820 | oled.print(cps);
821 | oled.setTextSize(1);
822 | if (cpm < 1000) {
823 | oled.setCursor(67, 16);
824 | } else {
825 | oled.setCursor(79, 16);
826 | }
827 | oled.print(" A:");
828 | oled.print(uploadcpm);
829 | oled.setCursor(127, 0);
830 | oled.setTextSize(2);
831 | oled.println();
832 | oled.println();
833 | oled.print("CPM:");
834 | if (cpm >= 1) {
835 | oled.println(cpm);
836 | }
837 | oled.setTextSize(1);
838 | oled.print("uSieverts/Hour:");
839 | oled.println(sieverts);
840 | oled.print("mSieverts/Year:");
841 | oled.println(svyear);
842 | if (cpm < 1000) {
843 | if (cpm >= 110) {
844 | barz = 7;
845 | } else if (cpm < 110 & cpm >= 35) {
846 | barz = 6;
847 | } else if (cpm < 35 & cpm >= 28) {
848 | barz = 5;
849 | } else if (cpm < 28 & cpm >= 23) {
850 | barz = 4;
851 | } else if (cpm < 23 & cpm >= 18) {
852 | barz = 3;
853 | } else if (cpm < 18 & cpm >= 13) {
854 | barz = 2;
855 | } else if (cpm < 13 & cpm >= 9) {
856 | barz = 1;
857 | } else {
858 | barz = 0;
859 | }
860 | for (int b = 0; b <= barz; b++) {
861 | oled.fillRect(90 + (b * 5), 43 - (b * 5), 3, b * 5, WHITE);
862 | }
863 | }
864 | oled.display();
865 | }
866 | void mediumData() { // Geiger data and graph ( max 110 cpm )
867 | oled.clearDisplay();
868 | oled.setCursor(0, 0);
869 | oled.setTextSize(1);
870 | oled.print("uSv/hr:");
871 | oled.print(sieverts);
872 | oled.setCursor(72, 0);
873 | oled.print("Avg:");
874 | oled.println(uploadcpm);
875 | oled.setCursor(0, 16);
876 | oled.setTextSize(1);
877 | oled.print("CPS: ");
878 | oled.setCursor(30, 8);
879 | oled.setTextSize(3);
880 | oled.println(cps);
881 | oled.setTextSize(1);
882 | oled.print("mSv/yr:");
883 | oled.println(svyear);
884 | oled.setTextSize(3);
885 | if (cpm >= 1) {
886 | oled.setCursor(0, 48);
887 | oled.setTextSize(1);
888 | oled.print("CPM: ");
889 | }
890 | oled.setCursor(30, 40);
891 | oled.setTextSize(3);
892 | oled.println(cpm);
893 | if (cpm >= 110) {
894 | barz = 7;
895 | } else if (cpm < 110 & cpm >= 35) {
896 | barz = 6;
897 | } else if (cpm < 35 & cpm >= 28) {
898 | barz = 5;
899 | } else if (cpm < 28 & cpm >= 23) {
900 | barz = 4;
901 | } else if (cpm < 23 & cpm >= 18) {
902 | barz = 3;
903 | } else if (cpm < 18 & cpm >= 13) {
904 | barz = 2;
905 | } else if (cpm < 13 & cpm >= 9) {
906 | barz = 1;
907 | } else {
908 | barz = 0;
909 | }
910 | for (int b = 0; b <= barz; b++) {
911 | oled.fillRect(90 + (b * 5), 35 - (b * 5), 3, b * 5, WHITE);
912 | }
913 | oled.display();
914 | }
915 | void largeData() { // Large count stats and background graph ( max 28 cpm )
916 | if (cpm >= 1000) {
917 | oled.clearDisplay();
918 | oled.setCursor(0, 0);
919 | oled.setTextSize(4);
920 | if (cpm >= 1) {
921 | oled.print(cps);
922 | }
923 | oled.setTextSize(1);
924 | oled.setCursor(75, 0);
925 | oled.println(timeClient.getFormattedTime());
926 | oled.setCursor(75, 8);
927 | if (statusCode >= 999)
928 | statusCode = 0;
929 | oled.print("U/L:");
930 | oled.println(statusCode);
931 | oled.setCursor(75, 16);
932 | oled.print("Avg:");
933 | oled.print(uploadcpm);
934 | oled.setCursor(127, 0);
935 | oled.setTextSize(4);
936 | oled.println();
937 | oled.println(cpm);
938 | oled.display();
939 | } else {
940 | oled.clearDisplay();
941 | oled.setCursor(0, 0);
942 | oled.setTextSize(4);
943 | if (cpm >= 1) {
944 | oled.print(cpm);
945 | }
946 | oled.setTextSize(1);
947 | oled.setCursor(69, 0);
948 | oled.println(timeClient.getFormattedTime());
949 | oled.setCursor(69, 8);
950 | if (statusCode >= 999)
951 | statusCode = 0;
952 | oled.println(statusCode);
953 | oled.setCursor(69, 16);
954 | oled.print(uploadcpm);
955 | oled.setCursor(127, 0);
956 | oled.setTextSize(4);
957 | oled.println();
958 | oled.println(cps);
959 | if (cpm >= 28) {
960 | barz = 19;
961 | } else if (cpm < 28 & cpm >= 27) {
962 | barz = 18;
963 | } else if (cpm < 27 & cpm >= 26) {
964 | barz = 17;
965 | } else if (cpm < 26 & cpm >= 24) {
966 | barz = 16;
967 | } else if (cpm < 24 & cpm >= 23) {
968 | barz = 15;
969 | } else if (cpm < 23 & cpm >= 22) {
970 | barz = 14;
971 | } else if (cpm < 22 & cpm >= 21) {
972 | barz = 13;
973 | } else if (cpm < 21 & cpm >= 20) {
974 | barz = 12;
975 | } else if (cpm < 20 & cpm >= 19) {
976 | barz = 11;
977 | } else if (cpm < 19 & cpm >= 18) {
978 | barz = 10;
979 | } else if (cpm < 18 & cpm >= 17) {
980 | barz = 9;
981 | } else if (cpm < 17 & cpm >= 16) {
982 | barz = 8;
983 | } else if (cpm < 16 & cpm >= 15) {
984 | barz = 7;
985 | } else if (cpm < 15 & cpm >= 14) {
986 | barz = 6;
987 | } else if (cpm < 14 & cpm >= 13) {
988 | barz = 5;
989 | } else if (cpm < 13 & cpm >= 12) {
990 | barz = 4;
991 | } else if (cpm < 12 & cpm >= 11) {
992 | barz = 3;
993 | } else if (cpm < 11 & cpm >= 10) {
994 | barz = 2;
995 | } else if (cpm < 10 & cpm >= 9) {
996 | barz = 1;
997 | } else {
998 | barz = 0;
999 | }
1000 | for (int b = 0; b <= barz; b++) {
1001 | oled.fillRect(27 + (b * 5), 60 - (b * 3), 3, b * 3, WHITE);
1002 | }
1003 | oled.display();
1004 | }
1005 | }
1006 |
1007 | void toggleWiFi() { //Toggle WIFI on/off
1008 | if (WIFIEnable == 1)
1009 | wifion();
1010 | if (WIFIEnable == 0) {
1011 | wifioff();
1012 | stopWiFiAndSleep();
1013 | }
1014 | oled.clearDisplay();
1015 | mode = oldmode;
1016 | }
1017 | void histogramData() { //Graph Data, autoscale max 16, 32, 64, 128, 256
1018 | oled.clearDisplay();
1019 | oled.setTextSize(1);
1020 | oled.setCursor(36, 0);
1021 | // oled.print("mSv/y: ");
1022 | oled.println(svyear);
1023 | oled.setCursor(80, 0);
1024 | oled.println(timeClient.getFormattedTime());
1025 | if (recenthi == 14) {
1026 | scale = 0.000488281;
1027 | } else if (recenthi == 13) {
1028 | scale = 0.000976562;
1029 | } else if (recenthi == 12) {
1030 | scale = 0.001953125;
1031 | } else if (recenthi == 11) {
1032 | scale = 0.00390625;
1033 | } else if (recenthi == 10) {
1034 | scale = 0.0078125;
1035 | } else if (recenthi == 9) {
1036 | scale = 0.015625;
1037 | } else if (recenthi == 8) {
1038 | scale = 0.03125;
1039 | } else if (recenthi == 7) {
1040 | scale = 0.0625;
1041 | } else if (recenthi == 6) {
1042 | scale = 0.125;
1043 | } else if (recenthi == 5) {
1044 | scale = 0.25;
1045 | } else if (recenthi == 4) {
1046 | scale = 0.5;
1047 | } else if (recenthi == 3) {
1048 | scale = 1;
1049 | } else if (recenthi == 2) {
1050 | scale = 2;
1051 | } else if (recenthi == 1) {
1052 | scale = 4;
1053 | } else if (recenthi == 0) {
1054 | scale = 8;
1055 | }
1056 | for (decltype(xpoints)::index_t i = 0; i <= xpoints.size(); i++) {
1057 | oled.fillRect(i + 12, 65 - (int(scale * xpoints[i])), 1, (int(scale * xpoints[i])), WHITE);
1058 | // Serial.print(xpoints[i]);
1059 | // Serial.println(int(scale * xpoints[i]));
1060 | for (decltype(xpoints)::index_t i = 0; i <= xpoints.size(); i++) {
1061 | if (xpoints[i] >= 65537) {
1062 | recenthi = 14;
1063 | scale14 = true;
1064 | }
1065 | if (xpoints[i] < 65537 && xpoints[i] >= 32769 && scale14 == false) {
1066 | recenthi = 13;
1067 | scale13 = true;
1068 | }
1069 | if (xpoints[i] < 32769 && xpoints[i] >= 16385 && scale14 == false && scale13 == false) {
1070 | recenthi = 12;
1071 | scale12 = true;
1072 | }
1073 | if (xpoints[i] < 16385 && xpoints[i] >= 8193 && scale14 == false && scale13 == false && scale12 == false) {
1074 | recenthi = 11;
1075 | scale11 = true;
1076 | }
1077 | if (xpoints[i] < 8193 && xpoints[i] >= 4097 && scale14 == false && scale13 == false && scale12 == false && scale11 == false) {
1078 | recenthi = 10;
1079 | scale10 = true;
1080 | }
1081 | if (xpoints[i] < 4097 && xpoints[i] >= 2049 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false) {
1082 | recenthi = 9;
1083 | scale9 = true;
1084 | }
1085 | if (xpoints[i] < 2049 && xpoints[i] >= 1025 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false) {
1086 | recenthi = 8;
1087 | scale8 = true;
1088 | }
1089 | if (xpoints[i] < 1025 && xpoints[i] >= 513 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false) {
1090 | recenthi = 7;
1091 | scale7 = true;
1092 | }
1093 | if (xpoints[i] < 513 && xpoints[i] >= 257 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false) {
1094 | recenthi = 6;
1095 | scale6 = true;
1096 | }
1097 | if (xpoints[i] < 257 && xpoints[i] >= 129 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false) {
1098 | recenthi = 5;
1099 | scale5 = true;
1100 | }
1101 | if (xpoints[i] < 129 && xpoints[i] >= 65 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false) {
1102 | recenthi = 4;
1103 | scale4 = true;
1104 | }
1105 | if (xpoints[i] < 65 && xpoints[i] >= 33 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false && scale4 == false) {
1106 | recenthi = 3;
1107 | scale3 = true;
1108 | }
1109 | if (xpoints[i] < 33 && xpoints[i] >= 17 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false && scale4 == false && scale3 == false) {
1110 | recenthi = 2;
1111 | scale2 = true;
1112 | }
1113 | if (xpoints[i] < 17 && xpoints[i] >= 9 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false && scale4 == false && scale3 == false && scale2 == false) {
1114 | recenthi = 1;
1115 | scale1 = true;
1116 | }
1117 | if (xpoints[i] < 9 && xpoints[i] >= 1 && scale14 == false && scale13 == false && scale12 == false && scale11 == false && scale10 == false && scale9 == false && scale8 == false && scale7 == false && scale6 == false && scale5 == false && scale4 == false && scale3 == false && scale2 == false && scale1 == false) {
1118 | recenthi = 0;
1119 | scale0 = true;
1120 | }
1121 | }
1122 | oled.setTextColor(WHITE);
1123 | oled.setTextSize(1);
1124 | oled.setCursor(0, 0);
1125 | if ((int(64 / scale) > 1023)) {
1126 | sprintf(buffer, "%dK", int(64 / scale / 1024));
1127 | oled.print(buffer);
1128 | } else {
1129 | oled.print(int(64 / scale));
1130 | }
1131 | oled.setCursor(0, 14);
1132 | if ((int(48 / scale) == 1536)) {
1133 | oled.print("1.5K");
1134 | }
1135 | if ((int(48 / scale) > 1536)) {
1136 | sprintf(buffer, "%dK", int(48 / scale / 1024));
1137 | oled.print(buffer);
1138 | }
1139 | if ((int(48 / scale) < 1536)) {
1140 | oled.print(int(48 / scale));
1141 | }
1142 | oled.setCursor(0, 28);
1143 | if ((int(32 / scale) > 1023)) {
1144 | sprintf(buffer, "%dK", int(32 / scale / 1024));
1145 | oled.print(buffer);
1146 | } else {
1147 | oled.print(int(32 / scale));
1148 | }
1149 | oled.setCursor(0, 42);
1150 | if ((int(16 / scale) > 1023)) {
1151 | sprintf(buffer, "%dK", int(16 / scale / 1024));
1152 | oled.print(buffer);
1153 | } else
1154 | oled.print(int(16 / scale));
1155 | oled.setCursor(0, 57);
1156 | oled.print("0");
1157 | oled.setTextColor(BLACK);
1158 | oled.setCursor(14, 48);
1159 | oled.setTextSize(2);
1160 | oled.print(cps);
1161 | if (cps < 100) {
1162 | oled.setTextSize(1);
1163 | oled.print("CPS");
1164 | }
1165 | oled.setCursor(58, 48);
1166 | oled.setTextSize(2);
1167 | if (xplot >= 1)
1168 | ;
1169 | {
1170 | oled.print(xplot);
1171 | }
1172 | oled.setTextSize(1);
1173 | oled.print("CPM");
1174 | oled.setCursor(115, 55);
1175 | // oled.print("U/L:");
1176 | if ((statusCode) == 200) {
1177 | oled.print("OK");
1178 | }
1179 | // else {
1180 | // oled.print("NA");
1181 | // }
1182 | }
1183 | scale0 = false;
1184 | scale1 = false;
1185 | scale2 = false;
1186 | scale3 = false;
1187 | scale4 = false;
1188 | scale5 = false;
1189 | scale6 = false;
1190 | scale7 = false;
1191 | scale8 = false;
1192 | scale9 = false;
1193 | scale10 = false;
1194 | scale11 = false;
1195 | scale12 = false;
1196 | scale13 = false;
1197 | scale14 = false;
1198 | oled.setTextColor(WHITE);
1199 | oled.display();
1200 | }
1201 |
1202 | //Monitor the serial connection from the geiger counter.
1203 | //If it is absent for > 15 seconds, display a warning
1204 | void serialmon() {
1205 | if (millis() > (geigerTimeout + 15000)) {
1206 | geigerConnected = false;
1207 | geigerconnected = ("false");
1208 | oled.clearDisplay();
1209 | oled.setTextSize(1);
1210 | oled.setCursor(0, 0);
1211 | oled.println(Release);
1212 | sprintf(buffer, "\nSerial NOT CONNECTED! \nCheck uart connection \nGPIO 27, # 6 on top from L to R");
1213 | oled.print(buffer);
1214 | oled.display();
1215 | APP_NAME = "serialmon:";
1216 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
1217 | syslog.log(LOG_INFO, "Geiger not connected! - Check serial port");
1218 | geigerTimeout = millis();
1219 | delay(3000);
1220 | }
1221 | }
1222 | // Grab, store and write softSerial data from GPIO 27 to geigerdata and geigerSerial
1223 | void grab() {
1224 | if (mySerial.available()) {
1225 | geigerdata = (mySerial.read());
1226 | geigerSerial += char(geigerdata);
1227 | delay(1);
1228 | }
1229 | }
1230 | //****Process data****
1231 | void process() {
1232 | if (geigerdata == 0x0D) { // \r CR detected
1233 | Log.loop();
1234 | geigerConnected = true; // Record that serial connection health is ok
1235 | geigerconnected = ("true"); // set the string for output
1236 | geigerTimeout = millis(); //gieger is connected, reset timer
1237 | // Parse CPS, CPM, and uS/hr from the string
1238 | int comma1Index = geigerSerial.indexOf(',');
1239 | int comma2Index = geigerSerial.indexOf(',', comma1Index + 1);
1240 | int comma3Index = geigerSerial.indexOf(',', comma2Index + 1);
1241 | int comma4Index = geigerSerial.indexOf(',', comma3Index + 1);
1242 | int comma5Index = geigerSerial.indexOf(',', comma4Index + 1);
1243 | int comma6Index = geigerSerial.indexOf(',', comma5Index + 1);
1244 | String cpsString = geigerSerial.substring(comma1Index + 1, comma2Index);
1245 | String cpmString = geigerSerial.substring(comma3Index + 1, comma4Index);
1246 | String sievertsString = geigerSerial.substring(comma5Index + 1, comma6Index);
1247 | cps = cpsString.toInt();
1248 | cpm = cpmString.toInt();
1249 | sieverts = sievertsString.toFloat();
1250 | webdata = geigerSerial;
1251 | Log.print(geigerSerial); // Output serial data via TLog
1252 | svyear = (sieverts * 8.76);
1253 | averagedata(); // get data averages
1254 | // grabgraphdata(); // grab data for mode 5 graph
1255 | geigerSerial = ""; // Clear the string for next time
1256 | flashblue(); // Heartbeat pulse
1257 | if (cps <= 5)
1258 | flashred(); // Flash red LED * CPS
1259 | else
1260 | digitalWrite(13, HIGH);
1261 | }
1262 | }
1263 |
1264 | // ********Setup*******
1265 | void setup() {
1266 | pinMode(13, OUTPUT); // setup LEDs
1267 | pinMode(0, OUTPUT); // setup LEDs
1268 | digitalWrite(0, LOW); // setup LEDs
1269 | digitalWrite(13, LOW); // setup LED
1270 | pinMode(buttonA, INPUT_PULLUP);
1271 | pinMode(buttonB, INPUT_PULLUP);
1272 | pinMode(buttonC, INPUT_PULLUP);
1273 | mySerial.begin(9600); // Start software serial link from Gieger
1274 | // Serial1.begin(9600); // Start hardware serial console
1275 | Serial.begin(115200); // Start hardware serial console
1276 | while (!Serial)
1277 | ; // wait for serial port to connect. Needed for Native USB only
1278 |
1279 | oled.init();
1280 | oled.setContrast(contrast); // reduce contrast to preserve OLED display
1281 |
1282 | // Animate bitmap
1283 | for (int i = -1; i <= 10; i++) {
1284 | oled.clearDisplay();
1285 | oled.drawBitmap(0, (62 - (6 * i)), bootupbitmap, 128, 60, WHITE);
1286 | oled.display();
1287 | }
1288 | delay(1500);
1289 |
1290 | Log.addPrintStream(std::make_shared(telnetSerialStream));
1291 | Log.addPrintStream(std::make_shared(webSerialStream));
1292 | wifion(); // Start wifi if enabled
1293 | Log.begin();
1294 | APP_NAME = "setup:";
1295 | Syslog syslog(udpClient, SYSLOG_SERVER, SYSLOG_PORT, DEVICE_HOSTNAME, APP_NAME, LOG_KERN);
1296 | syslog.logf(LOG_INFO, "%s", Release);
1297 | syslog.logf(LOG_INFO, "%s", releasedate);
1298 | syslog.log(LOG_INFO, "System Status: Online");
1299 | syslog.log(LOG_INFO, "Initial setup successful");
1300 | syslog.log(LOG_INFO, "Starting OTA update server");
1301 | ardota(); // Start Arduino OTA
1302 | cpmminavg.begin(); // Init moving average
1303 | cpmhouravg.begin(); // Init moving average
1304 | timerdelayavg.begin(); // Init moving average
1305 | timerdelaydayavg.begin(); // Init moving average
1306 | pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
1307 | ntpsetup(); // setup NTP client
1308 | mqttsetup(); // setup MQTT client
1309 | httpdsetup(); // setup HTTO server
1310 |
1311 | if (radmonen == true) {
1312 | syslog.log(LOG_INFO, "Starting radmon.org data feed");
1313 | xTaskCreatePinnedToCore(
1314 | radmon, /* Task function. */ // Upload to radmon.org every 60 secs using CPU0 as the HTTP GET takes some time
1315 | "Task1", /* name of task. */
1316 | 10000, /* Stack size of task */
1317 | NULL, /* parameter of the task */
1318 | 1, /* priority of the task */
1319 | &Task1, /* Task handle to keep track of created task */
1320 | 0); /* pin task to core 0 */
1321 | }
1322 | if (randomon == true) {
1323 | syslog.log(LOG_INFO, "Starting random generator");
1324 | xTaskCreatePinnedToCore(
1325 | randomise, /* Task function. */
1326 | "Task2", /* name of task. */
1327 | 10000, /* Stack size of task */
1328 | NULL, /* parameter of the task */
1329 | 1, /* priority of the task */
1330 | &Task2, /* Task handle to keep track of created task */
1331 | 0); /* pin task to core 0 */
1332 | }
1333 | if (randomon == true) {
1334 | pinMode(pulsepin, INPUT_PULLUP);
1335 | attachInterrupt(digitalPinToInterrupt(pulsepin), grabrandomnum, RISING);
1336 | }
1337 | if (MQTTEnable == true) {
1338 | syslog.log(LOG_INFO, "Starting MQTT client");
1339 | xTaskCreatePinnedToCore(
1340 | mqttpub, /* Task function. */ // Publish every 60 secs using CPU0 to MQTT Server
1341 | "Task3", /* name of task. */
1342 | 10000, /* Stack size of task */
1343 | NULL, /* parameter of the task */
1344 | 1, /* priority of the task */
1345 | &Task3, /* Task handle to keep track of created task */
1346 | 0); /* pin task to core 0 */
1347 |
1348 | if (mqttclient.connect(mqtt_id, mqtt_user, mqtt_password)) {
1349 | mqttclient.publish("WhyzaGC/status", "online");
1350 | }
1351 | }
1352 | syslog.log(LOG_INFO, "Setup is complete, entering main loop.....");
1353 | }
1354 |
1355 | // ****Main Loop****
1356 | void loop() {
1357 | serialmon(); // Monitor serial port for disconnection
1358 | grab(); // Grab MightyOhm serial data
1359 | process(); // Extract data and process
1360 | server.handleClient(); // Start Web diagnostics & data server on http://localip:80
1361 | logstats(); // Send hourly stats to syslog server
1362 | buttons(); // wait for button input and action
1363 | runntp(); // update NTP if setUpdateInterval in millis has expired
1364 | grabgraphdata(); // grab data for mode 4 histogram graph
1365 | if (randomon == true) {
1366 | echorandom();
1367 | }
1368 | ArduinoOTA.handle();
1369 | }
1370 |
--------------------------------------------------------------------------------