-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwifi-cw-keyer.ino
547 lines (327 loc) · 11.4 KB
/
wifi-cw-keyer.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
// Ver. 1.1 AVE RnD CW Keyer (20 / 12 /2022 )
//COMMENT - // 100% working script with ESP12 Wifi Module
// Upload and RUN "eeprom_clear.ino" even before uploading the real "wifi-cw-keyer.ino"
// After uploding this code (.ino) along with index.h - press restart the ESP12 Module
// Module will Run in AP mode and create a Wifi Hotspot named "92.168.4.1"
// Log in to that wifi network(no password needed) using a laptop computer or Mobile Smart phone
// Now , navigate to http://192.168.4.1/ using your web browser
// Type in English using default keyboard and that will be converted to Telegraphy messages ( via Pin 4) and send as Tone as well as digital out (via Pin 5)
//KEY_PIN and P_CW are = pin 5 of ESP12 > cw out pin
// tonepin is pin 4 of ESP12 , this for tone out through external speaker
// EEPROM STORES time_unit data - millisecond for DIT
// EEPROM also STORES side tone frequency - hertz for Side tone for telegraphy , though speaker
// On first loading , ESP12 recalls these two data from eeprom to html page for dispaying pre-saved data
// 3 numbers of input fields to type in a set GO the text as CW
#include <EEPROM.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include "index.h" //Our HTML webpage contents with javascripts
// EEPROM STORAGE variables
String data;
void writeString(char add,String data);
String read_String(char add);
String recivedData;
int count = 0;
int last_sent_location=0;
int messagetocw();
#define P_CW 5 // ESP12- (GPIO 10) // CW digital output
int KEY_PIN=5; // relay drive to transimit cw in port of ESP8266
int sm_time;
int TIME_UNIT = 73; // default time for DIT
bool dxing_mode = true; // put false for normal mode
String morsecode;
String message;
String dit_time;
String freq;
int present_message_length;
String backup_message;
String present_message;
int tonepin = 4;
int my_tone_frequency = 500;
const String characters = "abcdefghijklmnopqrstuvwxyz1234567890?.,/-; ";
////////////////////////////// CW sender/////
String mappings[] = {
".-", // A
"-...",
"-.-.",
"-..",
".",
"..-.",
"--.",
"....",
"..",
".---",
"-.-",
".-..",
"--",
"-.",
"---",
".--.",
"--.-",
".-.",
"...",
"-",
"..-",
"...-",
".--",
"-..-",
"-.--",
"--..", // Z
".----", // 1
"..---",
"...--",
"....-",
".....",
"-....",
"--...",
"---..",
"----.",
"-----", // 0
"..--..", // ?
".-.-.-", // .
"--..--", // ,
"-..-.", // /
"-...-", // - // spacing symbol
".-.-." , // ; // "AR" symbol
""
};
//SSID and Password of your WiFi router
const char* ssid = "192.168.4.1";
const char* password = "";
ESP8266WebServer server(80); //Server on port 80
//===============================================================
// This routine is executed when you open its IP in browser
//===============================================================
void handleRoot() {
String s = MAIN_page; //Read HTML contents on index.h
server.send(200, "text/html", s); //Send web page
}
void handleWPMTXT(){
dit_time = server.arg("mytxt");
Serial.println("received dit_time is :");
Serial.println(dit_time);
Serial.println("");
server.send(200, "text/plane", dit_time);
// store eeprom to continue here...
data = dit_time;
Serial.print("Writing Data to address 0:");
Serial.println(data);
//WRITING NEW WPM DATA (DIT TIME IN MILLISECOND) IN EEPROM
writeString(0, data); //Address 0 and String type data
delay(10);
TIME_UNIT = data.toInt(); // CONVERTING STRING TO INT and STORING IN TIME_UNIT (NEW WPM STORED )
}
void handleWPMBACK(){
//////// DISPLAY STORED WPM IN HTML FILE
recivedData = read_String(0);
Serial.print("Read Data OF WPM FROM 0:");
Serial.println(recivedData);
delay(1000);
server.send(200, "text/plane", recivedData);
}
void handleTONEBACK(){
//////// DISPLAY STORED TONE FREQUENCY IN HTML FILE
recivedData = read_String(10);
Serial.print("Read Data OF WPM FROM 10:");
Serial.println(recivedData);
delay(1000);
server.send(200, "text/plane", recivedData);
}
/////////////////------------
void handleTONETXT(){
freq = server.arg("mytxt");
Serial.println("received frequency is :");
Serial.println(freq );
Serial.println("");
server.send(200, "text/plane", freq);
// store eeprom to continue here...
data = freq;
Serial.print("Writing Data to address 10:");
Serial.println(data);
//WRITING NEW SIDE TONE FREQUENCY DATA (FREQUENCY IN HERTZ) IN EEPROM
writeString(10, data); //Address 10 and String type data
delay(10);
my_tone_frequency = data.toInt(); // CONVERTING STRING TO INT and STORING IN my_tone_frequency (NEW frequency STORED )
}
//////////////////---------------
//-----------ave edit
void handleCWTXT(){
message = server.arg("mytxt");
Serial.println(message);
server.send(200, "text/plane", message);
present_message = message;
message="";
//int result= messagetocw();
}
//-----------ave edit
//==============================================================
// SETUP
//==============================================================
void setup(void){
pinMode(P_CW, OUTPUT);
pinMode(KEY_PIN, OUTPUT);
pinMode(tonepin, OUTPUT);
// send the FIRST CHARACTOR ONLY of the subscribed string as cw
// int result= messagetocw();
// reserve 200 bytes for the inputString:
// inputString.reserve(200);
Serial.begin(115200);
EEPROM.begin(512);
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.on("/", handleRoot); //Which routine to handle at root location. This is display page
server.on("/cwtxt", handleCWTXT);
server.on("/wpmtxt", handleWPMTXT);
server.on("/tonetxt", handleTONETXT);
server.on("/wpmback", handleWPMBACK);
server.on("/toneback", handleTONEBACK);
server.begin(); //Start server
Serial.println("");
Serial.println("HTTP server started");
Serial.print("EEPROM length: ");
Serial.println(EEPROM.length());
// FOR FIRST RUN >> WPM VALUE FROM EEPROM TO RUNNING PROGRAMME
// reading eeprom value of TIME_UNIT from address 0, to store in TIME_UNIT
recivedData = read_String(0);
Serial.print("Read Data from address 0 : ");
Serial.println(recivedData);
delay(1000);
if(recivedData.length() >=1){
TIME_UNIT = recivedData.toInt(); // CONVERTING STRING TO INT and STORING IN TIME_UNIT (NEW WPM STORED )
}else{
TIME_UNIT = 100;
}
// reading eeprom value of TIME_UNIT from address 0, to store in TIME_UNIT
// FOR FIRST RUN >> FREQUENCY VALUE FROM EEPROM TO RUNNING PROGRAMME
// reading eeprom value of my_tone_frequency from address 10, to store in my_tone_frequency
recivedData = read_String(10);
Serial.print("Read Data from address 10 : ");
Serial.println(recivedData);
delay(1000);
if(recivedData.length() >=1){
my_tone_frequency = recivedData.toInt(); // CONVERTING STRING TO INT and STORING IN my_tone_frequency (NEW SIDE TONE FREQUENCY STORED )
}else {
my_tone_frequency = 1000;
}
// reading eeprom value of TIME_UNIT from address 0, to store in TIME_UNIT
}
//==============================================================
// LOOP
//==============================================================
void loop(void){
int result= messagetocw(); // WHOLE STRING sending string as cw
server.handleClient(); //Handle client requests
}
int messagetocw()
{
// FUNCTION messagetocw() START
// int size = strlen(message);
present_message_length = present_message.length();
if(last_sent_location > present_message_length)
{
last_sent_location = present_message_length;
}
// int TIME_UNIT = 50; // default time for DIT
// const int DOT = TIME_UNIT;
// const int DASH = 3 * TIME_UNIT;
// const int SYMBOL_SPACE = TIME_UNIT;
//const int LETTER_SPACE = 3 * TIME_UNIT - SYMBOL_SPACE;
// const int WORD_SPACE = 7 * TIME_UNIT - LETTER_SPACE;
const int DOT = TIME_UNIT;
const int DASH = 3 * TIME_UNIT;
int ss;
int ls;
int ws;
if(dxing_mode)
{
ss=DOT;
ls=0.2 * DOT;
ws=1 * DOT;
}
else
{
ss=DOT;
ls=2 * DOT;
ws=5 * DOT;
}
const int SYMBOL_SPACE = ss;
const int LETTER_SPACE = ls;
const int WORD_SPACE = ws;
present_message.toLowerCase();
// for (int i = 0; i < size; i++) {
// const char* ch = strchr(characters, tolower(message[i]));
char ch = characters.charAt(characters.indexOf(present_message.charAt(last_sent_location)));//
// if (ch != NULL){
if (ch != '\0'){
// int position = ch-characters;
int position = characters.indexOf(present_message.charAt(last_sent_location));
last_sent_location=last_sent_location+1;
morsecode = mappings[position];
// int count = strlen(morsecode);
int count = morsecode.length();
for( int j=0; j< count; j++)
{
char symbol = morsecode[j];
if(symbol =='.')
{
sm_time = DOT;
}
if(symbol =='-')
{
sm_time = DASH;
}
digitalWrite(KEY_PIN, HIGH);
tone(tonepin, my_tone_frequency);
delay(sm_time);
digitalWrite(KEY_PIN, LOW);
noTone(tonepin);
delay(SYMBOL_SPACE);
}// for loop close2
delay(LETTER_SPACE);
}
delay(WORD_SPACE);
// }// for loop close1
return 0;
} // FUNCTION messagetocw() close
//////// EEPROM WRITE / READ FUNCTIONS ///////////
void writeString(char add,String data)
{
int _size = data.length();
int i;
for(i=0;i<_size;i++)
{
EEPROM.write(add+i,data[i]);
}
EEPROM.write(add+_size,'\0'); //Add termination null character for String Data
EEPROM.commit();
}
String read_String(char add)
{
int i;
char data[100]; //Max 100 Bytes
int len=0;
unsigned char k;
k=EEPROM.read(add);
while(k != '\0' && len<500) //Read until null character
{
k=EEPROM.read(add+len);
data[len]=k;
len++;
}
data[len]='\0';
return String(data);
}
//////// EEPROM WRITE / READ FUNCTIONS ///////////
// Key the transmitter // lambic keyer
void keyAndBeep(int speed)
{
digitalWrite(P_CW, HIGH); // Key down
for (int i=0; i < speed; i++) // Beep loop
{
delay(2);
}
digitalWrite(P_CW, LOW); // Key up
}