-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSonosUPnP.cpp
2493 lines (2207 loc) · 91.2 KB
/
SonosUPnP.cpp
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/************************************************************************/
/* Sonos UPnP, an UPnP based read/write remote control library, v1.1. */
/* */
/* This library is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This library is distributed in the hope that it will be useful, but */
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this library. If not, see <http://www.gnu.org/licenses/>. */
/* */
/* Written by Thomas Mittet ([email protected]) January 2015. */
/************************************************************************/
#include <TFT_eSPI.h>
extern TFT_eSPI tft;
//extern void ethConnectError(void);
extern void TFT_line_print(int line, const char *content);
extern void UpdateLCD(void);
#include "SonosUPnP.h"
//int strpos(const char *haystack, const char *needle)
//{
// const char *p = strstr(haystack, needle);
// if (p)
// return p - haystack;
// return -1;
//}
const char p_HttpVersion[] PROGMEM = HTTP_VERSION;
const char p_HeaderHost[] PROGMEM = HEADER_HOST;
const char p_HeaderContentType[] PROGMEM = HEADER_CONTENT_TYPE;
const char p_HeaderContentLength[] PROGMEM = HEADER_CONTENT_LENGTH;
const char p_HeaderSoapAction[] PROGMEM = HEADER_SOAP_ACTION;
const char p_HeaderConnection[] PROGMEM = HEADER_CONNECTION;
const char p_SoapEnvelopeStart[] PROGMEM = SOAP_ENVELOPE_START;
const char p_SoapEnvelopeEnd[] PROGMEM = SOAP_ENVELOPE_END;
const char p_SoapBodyStart[] PROGMEM = SOAP_BODY_START;
const char p_SoapBodyEnd[] PROGMEM = SOAP_BODY_END;
const char p_SoapEnvelope[] PROGMEM = SOAP_TAG_ENVELOPE;
const char p_SoapBody[] PROGMEM = SOAP_TAG_BODY;
const char p_UpnpUrnSchema[] PROGMEM = UPNP_URN_SCHEMA;
const char p_UpnpAvTransportService[] PROGMEM = UPNP_AV_TRANSPORT_SERVICE;
const char p_UpnpAvTransportEndpoint[] PROGMEM = UPNP_AV_TRANSPORT_ENDPOINT;
const char p_UpnpRenderingControlService[] PROGMEM = UPNP_RENDERING_CONTROL_SERVICE;
const char p_UpnpRenderingControlEndpoint[] PROGMEM = UPNP_RENDERING_CONTROL_ENDPOINT;
const char p_UpnpDevicePropertiesService[] PROGMEM = UPNP_DEVICE_PROPERTIES_SERVICE;
const char p_UpnpDevicePropertiesEndpoint[] PROGMEM = UPNP_DEVICE_PROPERTIES_ENDPOINT;
const char p_UpnpContentDirectoryService[] PROGMEM = UPNP_CONTENT_DIRECTORY_SERVICE;
const char p_UpnpContentDirectoryEndpoint[] PROGMEM = UPNP_CONTENT_DIRECTORY_ENDPOINT;
const char p_GetZoneAttributesA [] = PROGMEM SONOS_TAG_GET_ZONE_ATTR;
const char p_GetZoneAttributesR [] = PROGMEM SONOS_TAG_GET_ZONE_ATTR_RESPONSE;
const char p_ZoneName[] = PROGMEM SONOS_TAG_ZONENAME ;
const char p_GetZoneInfoA [] = PROGMEM SONOS_TAG_GET_ZONE_INFO;
const char p_GetZoneInfoR [] = PROGMEM SONOS_TAG_GET_ZONE_INFO_RESPONSE;
const char p_Serial[] = PROGMEM SONOS_TAG_SERIAL ;
const char p_ZPSupportInfo[] = PROGMEM SONOS_GET_ZPSUPPORTINFO;
const char p_ZPInfo[] = PROGMEM SONOS_GET_ZPINFO;
const char p_ZPZone[] = PROGMEM SONOS_GET_ZPZONE;
const char p_ZPLocalUID[] = PROGMEM SONOS_GET_ZPLOCALUID;
const char p_ZPSerial[] = PROGMEM SONOS_GET_ZPSERIAL;
const char p_ZPSeriesID[] = PROGMEM SONOS_GET_ZPSERIESID;
const char p_Play[] PROGMEM = SONOS_TAG_PLAY;
const char p_SourceRinconTemplate[] PROGMEM = SONOS_SOURCE_RINCON_TEMPLATE;
const char p_Stop[] PROGMEM = SONOS_TAG_STOP;
const char p_Pause[] PROGMEM = SONOS_TAG_PAUSE;
const char p_Previous[] PROGMEM = SONOS_TAG_PREVIOUS;
const char p_Next[] PROGMEM = SONOS_TAG_NEXT;
const char p_InstenceId0Tag[] PROGMEM = SONOS_INSTANCE_ID_0_TAG;
const char p_Seek[] PROGMEM = SONOS_TAG_SEEK;
const char p_SeekModeTagStart[] PROGMEM = SONOS_SEEK_MODE_TAG_START;
const char p_SeekModeTagEnd[] PROGMEM = SONOS_SEEK_MODE_TAG_END;
const char p_TimeFormatTemplate[] PROGMEM = SONOS_TIME_FORMAT_TEMPLATE;
const char p_SetAVTransportURI[] PROGMEM = SONOS_TAG_SET_AV_TRANSPORT_URI;
const char p_UriMetaLightStart[] PROGMEM = SONOS_URI_META_LIGHT_START;
const char p_UriMetaLightEnd[] PROGMEM = SONOS_URI_META_LIGHT_END;
const char p_RadioMetaFullStart[] PROGMEM = SONOS_RADIO_META_FULL_START;
const char p_RadioMetaFullEnd[] PROGMEM = SONOS_RADIO_META_FULL_END;
const char p_BecomeCoordinatorOfStandaloneGroup[] PROGMEM = SONOS_TAG_BECOME_COORDINATOR_OF_STANDALONE_GROUP;
const char p_SetLEDState[] PROGMEM = SONOS_TAG_SET_LED_STATE;
const char p_AddURIToQueue[] PROGMEM = SONOS_TAG_ADD_URI_TO_QUEUE;
const char p_SavedQueues[] PROGMEM = SONOS_SAVED_QUEUES;
const char p_RemoveAllTracksFromQueue[] PROGMEM = SONOS_TAG_REMOVE_ALL_TRACKS_FROM_QUEUE;
const char p_PlaylistMetaLightStart[] PROGMEM = SONOS_PLAYLIST_META_LIGHT_START;
const char p_PlaylistMetaLightEnd[] PROGMEM = SONOS_PLAYLIST_META_LIGHT_END;
const char p_GetPositionInfoA[] PROGMEM = SONOS_TAG_GET_POSITION_INFO;
const char p_GetPositionInfoR[] PROGMEM = SONOS_TAG_GET_POSITION_INFO_RESPONSE;
const char p_Track[] PROGMEM = SONOS_TAG_TRACK;
const char p_NrTracks[] PROGMEM = SONOS_TAG_NRTRACKS;
const char p_TrackDuration[] PROGMEM = SONOS_TAG_TRACK_DURATION;
const char p_MediaDuration[] PROGMEM = SONOS_TAG_MEDIA_DURATION;
const char p_TrackURI[] PROGMEM = SONOS_TAG_TRACK_URI;
const char p_CurrentURI[] PROGMEM = SONOS_TAG_CURRENT_URI;
const char p_RelTime[] PROGMEM = SONOS_TAG_REL_TIME;
const char p_TrackMetaData[] PROGMEM = SONOS_TAG_TRACK_METADATA;
// nieuw
const char p_TrackMeta[] PROGMEM = SONOS_TAG_TRACKMETA;
const char p_TrackTitle[] PROGMEM = SONOS_ATTRIB_TITLE;
const char p_TrackCreator[] PROGMEM = SONOS_ATTRIB_CREATOR;
const char p_TrackAlbum[] PROGMEM = SONOS_ATTRIB_ALBUM;
const char p_TrackArtist[] PROGMEM = SONOS_ATTRIB_ARTIST;
const char p_GetMediaInfoA[] PROGMEM = SONOS_TAG_GET_MEDIA_INFO;
const char p_GetMediaInfoR[] PROGMEM = SONOS_TAG_GET_MEDIA_INFO_RESPONSE;
const char p_CurrentURIMetaData[] PROGMEM = SONOS_TAG_CURRENTURIMETADATA;
// ******************************************************************************************************************************************
const char p_BrowseA[] PROGMEM = SONOS_TAG_BROWSE;
const char p_BrowseR[] PROGMEM = SONOS_TAG_BROWSE_RESPONSE;
const char p_GetMuteA[] PROGMEM = SONOS_TAG_GET_MUTE;
const char p_GetMuteR[] PROGMEM = SONOS_TAG_GET_MUTE_RESPONSE;
const char p_CurrentMute[] PROGMEM = SONOS_TAG_CURRENT_MUTE;
const char p_GetVolumeA[] PROGMEM = SONOS_TAG_GET_VOLUME;
const char p_GetVolumeR[] PROGMEM = SONOS_TAG_GET_VOLUME_RESPONSE;
const char p_CurrentVolume[] PROGMEM = SONOS_TAG_CURRENT_VOLUME;
const char p_GetOutputFixedA[] PROGMEM = SONOS_TAG_GET_OUTPUT_FIXED;
const char p_GetOutputFixedR[] PROGMEM = SONOS_TAG_GET_FIXED_RESPONSE;
const char p_CurrentFixed[] PROGMEM = SONOS_TAG_CURRENT_FIXED;
const char p_GetBassA[] PROGMEM = SONOS_TAG_GET_BASS;
const char p_GetBassR[] PROGMEM = SONOS_TAG_GET_BASS_RESPONSE;
const char p_CurrentBass[] PROGMEM = SONOS_TAG_CURRENT_BASS;
const char p_GetTrebleA[] PROGMEM = SONOS_TAG_GET_TREBLE;
const char p_GetTrebleR[] PROGMEM = SONOS_TAG_GET_TREBLE_RESPONSE;
const char p_CurrentTreble[] PROGMEM = SONOS_TAG_CURRENT_TREBLE;
const char p_GetLoudnessA[] PROGMEM = SONOS_TAG_GET_LOUDNESS;
const char p_GetLoudnessR[] PROGMEM = SONOS_TAG_GET_LOUDNESS_RESPONSE;
const char p_CurrentLoudness[] PROGMEM = SONOS_TAG_CURRENT_LOUDNESS;
const char p_SetMute[] PROGMEM = SONOS_TAG_SET_MUTE;
const char p_SetVolume[] PROGMEM = SONOS_TAG_SET_VOLUME;
const char p_SetBass[] PROGMEM = SONOS_TAG_SET_BASS;
const char p_SetTreble[] PROGMEM = SONOS_TAG_SET_TREBLE;
const char p_SetLoudness[] PROGMEM = SONOS_TAG_SET_LOUDNESS;
const char p_ChannelTagStart[] PROGMEM = SONOS_CHANNEL_TAG_START;
const char p_ChannelTagEnd[] PROGMEM = SONOS_CHANNEL_TAG_END;
const char p_GetTransportSettingsA[] PROGMEM = SONOS_TAG_GET_TRANSPORT_SETTINGS;
const char p_GetTransportSettingsR[] PROGMEM = SONOS_TAG_GET_TRANSPORT_SETTINGS_RESPONSE;
const char p_PlayMode[] PROGMEM = SONOS_TAG_PLAY_MODE;
const char p_SetPlayMode[] PROGMEM = SONOS_TAG_SET_PLAY_MODE;
const char p_GetTransportInfoA[] PROGMEM = SONOS_TAG_GET_TRANSPORT_INFO;
const char p_GetTransportInfoR[] PROGMEM = SONOS_TAG_GET_TRANSPORT_INFO_RESPONSE;
const char p_CurrentTransportState[] PROGMEM = SONOS_TAG_CURRENT_TRANSPORT_STATE;
const char p_GetMediaMetadata[] PROGMEM = SONOS_TAG_GET_MEDIAMETADATA; // frank 24JUL20
const char p_GetMediaMetadataResponse[] PROGMEM = SONOS_TAG_GET_MEDIAMETADATARESPONSE; // frank 24JUL20
const char p_GetMediaMetadataResult[] PROGMEM = SONOS_TAG_GET_MEDIAMETADATARESULT; // frank 24JUL20
const char p_Id[] PROGMEM = SONOS_TAG_ID; // frank 24JUL20
const char p_Title[] PROGMEM = SONOS_TAG_TITLE; // frank 24JUL20
const char p_CurrentMedium[] PROGMEM = SONOS_TAG_MEDIUM_STATUS;
const char p_CurrentArtist[] PROGMEM = SONOS_TAG_ARTIST_STATUS;
const char p_UPnPBroadcast[] PROGMEM = UPNP_DEVICE_SCAN;
const char *p_MediaSource[SONOS_MAXSOURCE]={
SONOS_SOURCE_UNKNOWN_SCHEME,
SONOS_SOURCE_SPOTIFY_SCHEME,
SONOS_SOURCE_FILE_SCHEME,
SONOS_SOURCE_LIBRARY_SCHEME,
SONOS_SOURCE_HTTP_SCHEME,
SONOS_SOURCE_RADIO_SCHEME,
SONOS_SOURCE_RADIO_AAC_SCHEME,
SONOS_SOURCE_LINEIN_SCHEME,
SONOS_SOURCE_MASTER_SCHEME,
SONOS_SOURCE_QUEUE_SCHEME,
SONOS_SOURCE_SPOTIFYSTATION_SCHEME,
SONOS_SOURCE_LOCALHTTP_SCHEME,
SONOS_SOURCE_LOCALHTTPS_SCHEME,
SONOS_SOURCE_SPOTIFY_RADIO_SCHEME };
const char *p_MediaSourceName[SONOS_MAXSOURCE]={
UNKNOWN_SCHEME,
SPOTIFY_SCHEME,
FILE_SCHEME,
LIBRARY_SCHEME,
HTTP_SCHEME,
RADIO_SCHEME,
RADIO_AAC_SCHEME,
LINEIN_SCHEME,
MASTER_SCHEME,
QUEUE_SCHEME,
SPOTIFYSTATION_SCHEME,
LOCALHTTP_SCHEME,
LOCALHTTPS_SCHEME,
SPOTIFY_RADIO_SCHEME };
#define SELECTSONG 1 // Bepaalt Led Scanner en Jukebox gedrag
#define SELECTRADIO 0 // Bepaalt Led Scanner en Jukebox gedrag
// new local Data Variables - is increasing footprint, but easies passing of extra char-string-info
char CREATOR_BUFFER[76] = "\0";
char ARTIST_BUFFER[76] = "\0";
char TITLE_BUFFER[100] = "\0";
char ALBUM_BUFFER[92] = "\0";
char DURATION_BUFFER[16]= "\0";
char POSITION_BUFFER[16]= "\0";
char ZONE_BUFFER[32]= "\0";
char UID_BUFFER[32]= "\0";
char SERIAL_BUFFER[24]= "\0";
char SERIESID_BUFFER[24]= "\0";
char MEDIUM_BUFFER[16]= "\0";
char STATUS_BUFFER[16]= "\0";
char PLAYMODE_BUFFER[16]= "\0";
char SOURCE_BUFFER[16]= "\0";
SonosUPnP::SonosUPnP(WiFiClient client, void (*ethernetErrCallback)(void))
{
#ifndef SONOS_WRITE_ONLY_MODE
this->xPath = MicroXPath_P();
#endif
this->ethClient = client;
this->ethernetErrCallback = ethernetErrCallback;
}
void SonosUPnP::setAVTransportURI(IPAddress speakerIP, const char *scheme, const char *address)
{
setAVTransportURI(speakerIP, scheme, address, p_UriMetaLightStart, p_UriMetaLightEnd, "");
}
void SonosUPnP::seekTrack(IPAddress speakerIP, uint16_t index)
{
char indexChar[6];
itoa(index, indexChar, 10);
seek(speakerIP, SONOS_SEEK_MODE_TRACK_NR, indexChar);
}
void SonosUPnP::seekTime(IPAddress speakerIP, uint8_t hour, uint8_t minute, uint8_t second)
{
char time[11];
sprintf_P(time, p_TimeFormatTemplate, hour, minute, second);
seek(speakerIP, SONOS_SEEK_MODE_REL_TIME, time);
}
void SonosUPnP::setPlayMode(IPAddress speakerIP, uint8_t playMode)
{
const char *playModeValue;
switch (playMode)
{
case SONOS_PLAY_MODE_REPEAT:
playModeValue = SONOS_PLAY_MODE_REPEAT_VALUE;
break;
case SONOS_PLAY_MODE_SHUFFLE_REPEAT:
playModeValue = SONOS_PLAY_MODE_SHUFFLE_REPEAT_VALUE;
break;
case SONOS_PLAY_MODE_SHUFFLE:
playModeValue = SONOS_PLAY_MODE_SHUFFLE_VALUE;
break;
default:
playModeValue = SONOS_PLAY_MODE_NORMAL_VALUE;
break;
}
upnpSet(speakerIP, UPNP_AV_TRANSPORT, p_SetPlayMode, SONOS_TAG_NEW_PLAY_MODE, playModeValue);
}
void SonosUPnP::play(IPAddress speakerIP)
{
upnpSet(speakerIP, UPNP_AV_TRANSPORT, p_Play, SONOS_TAG_SPEED, "1");
}
void SonosUPnP::playFile(IPAddress speakerIP, const char *path)
{
setAVTransportURI(speakerIP, SONOS_SOURCE_FILE_SCHEME, path);
play(speakerIP);
}
void SonosUPnP::playHttp(IPAddress speakerIP, const char *address)
{
// "x-sonos-http:" does not work for me etAVTransportURI(speakerIP, SONOS_SOURCE_HTTP_SCHEME, address);
setAVTransportURI(speakerIP, "", address);
play(speakerIP);
}
void SonosUPnP::playRadio(IPAddress speakerIP, const char *address, const char *title)
{
setAVTransportURI(speakerIP, SONOS_SOURCE_RADIO_SCHEME, address, p_RadioMetaFullStart, p_RadioMetaFullEnd, title);
play(speakerIP);
}
void SonosUPnP::playLineIn(IPAddress speakerIP, const char *speakerID)
{
char address[30];
sprintf_P(address, p_SourceRinconTemplate, speakerID, UPNP_PORT, "");
setAVTransportURI(speakerIP, SONOS_SOURCE_LINEIN_SCHEME, address);
play(speakerIP);
}
void SonosUPnP::playQueue(IPAddress speakerIP, const char *speakerID)
{
char address[30];
sprintf_P(address, p_SourceRinconTemplate, speakerID, UPNP_PORT, "#0");
setAVTransportURI(speakerIP, SONOS_SOURCE_QUEUE_SCHEME, address);
play(speakerIP);
}
void SonosUPnP::playConnectToMaster(IPAddress speakerIP, const char *masterSpeakerID)
{
char address[30];
sprintf_P(address, p_SourceRinconTemplate, masterSpeakerID, UPNP_PORT, "");
setAVTransportURI(speakerIP, SONOS_SOURCE_MASTER_SCHEME, address);
}
void SonosUPnP::disconnectFromMaster(IPAddress speakerIP)
{
upnpSet(speakerIP, UPNP_AV_TRANSPORT, p_BecomeCoordinatorOfStandaloneGroup);
}
// deze wordt alleen aangeroepen als er een fout is? En dan de sonos nog commanderen om te stoppen?
void SonosUPnP::stop(IPAddress speakerIP)
{
upnpSet(speakerIP, UPNP_AV_TRANSPORT, p_Stop);
}
void SonosUPnP::pause(IPAddress speakerIP)
{
upnpSet(speakerIP, UPNP_AV_TRANSPORT, p_Pause);
}
void SonosUPnP::skip(IPAddress speakerIP, uint8_t direction)
{
upnpSet(
speakerIP, UPNP_AV_TRANSPORT, direction == SONOS_DIRECTION_FORWARD ? p_Next : p_Previous);
}
void SonosUPnP::setMute(IPAddress speakerIP, bool state)
{
upnpSet(
speakerIP, UPNP_RENDERING_CONTROL, p_SetMute,
SONOS_TAG_DESIRED_MUTE, state ? "1" : "0", "", p_ChannelTagStart, p_ChannelTagEnd, SONOS_CHANNEL_MASTER);
}
void SonosUPnP::setVolume(IPAddress speakerIP, uint8_t volume)
{
setVolume(speakerIP, volume, SONOS_CHANNEL_MASTER);
}
void SonosUPnP::setVolume(IPAddress speakerIP, uint8_t volume, const char *channel)
{
if (volume > 100) volume = 100;
char volumeChar[4];
itoa(volume, volumeChar, 10);
upnpSet(
speakerIP, UPNP_RENDERING_CONTROL, p_SetVolume,
SONOS_TAG_DESIRED_VOLUME, volumeChar, "", p_ChannelTagStart, p_ChannelTagEnd, channel);
}
void SonosUPnP::setBass(IPAddress speakerIP, int8_t bass)
{
bass = constrain(bass, -10, 10);
char bassChar[4];
itoa(bass, bassChar, 10);
upnpSet(
speakerIP, UPNP_RENDERING_CONTROL, p_SetBass,
SONOS_TAG_DESIRED_BASS, bassChar);
}
void SonosUPnP::setTreble(IPAddress speakerIP, int8_t treble)
{
treble = constrain(treble, -10, 10);
char trebleChar[4];
itoa(treble, trebleChar, 10);
upnpSet(
speakerIP, UPNP_RENDERING_CONTROL, p_SetTreble,
SONOS_TAG_DESIRED_TREBLE, trebleChar);
}
void SonosUPnP::setLoudness(IPAddress speakerIP, bool state)
{
upnpSet(
speakerIP, UPNP_RENDERING_CONTROL, p_SetLoudness,
SONOS_TAG_DESIRED_LOUDNESS, state ? "1" : "0", "", p_ChannelTagStart, p_ChannelTagEnd, SONOS_CHANNEL_MASTER);
}
void SonosUPnP::setStatusLight(IPAddress speakerIP, bool state)
{
upnpSet(
speakerIP, UPNP_DEVICE_PROPERTIES, p_SetLEDState,
SONOS_TAG_DESIRED_LED_STATE, state ? "On" : "Off");
}
void SonosUPnP::addPlaylistToQueue(IPAddress speakerIP, uint16_t playlistIndex)
{
char path[45];
sprintf_P(path, p_SavedQueues, playlistIndex);
addTrackToQueue(speakerIP, "", path);
}
void SonosUPnP::addTrackToQueue(IPAddress speakerIP, const char *scheme, const char *address)
{
upnpSet(
speakerIP, UPNP_AV_TRANSPORT, p_AddURIToQueue,
SONOS_TAG_ENQUEUED_URI, scheme, address, p_PlaylistMetaLightStart, p_PlaylistMetaLightEnd, "");
}
void SonosUPnP::removeAllTracksFromQueue(IPAddress speakerIP)
{
upnpSet(speakerIP, UPNP_AV_TRANSPORT, p_RemoveAllTracksFromQueue);
}
#ifndef SONOS_WRITE_ONLY_MODE
void SonosUPnP::setRepeat(IPAddress speakerIP, bool repeat)
{
bool current = getRepeat(speakerIP);
if (repeat != current)
{
setPlayMode(speakerIP, current ^ SONOS_PLAY_MODE_REPEAT);
}
}
void SonosUPnP::setShuffle(IPAddress speakerIP, bool shuffle)
{
bool current = getShuffle(speakerIP);
if (shuffle != current)
{
setPlayMode(speakerIP, current ^ SONOS_PLAY_MODE_SHUFFLE);
}
}
void SonosUPnP::toggleRepeat(IPAddress speakerIP)
{
setPlayMode(speakerIP, getPlayMode(speakerIP) ^ SONOS_PLAY_MODE_REPEAT);
}
void SonosUPnP::toggleShuffle(IPAddress speakerIP)
{
setPlayMode(speakerIP, getPlayMode(speakerIP) ^ SONOS_PLAY_MODE_SHUFFLE);
}
void SonosUPnP::togglePause(IPAddress speakerIP)
{
uint8_t state = getState(speakerIP);
if (state == SONOS_STATE_PLAYING)
{
pause(speakerIP);
}
else if (state == SONOS_STATE_PAUSED)
{
play(speakerIP);
}
}
void SonosUPnP::toggleMute(IPAddress speakerIP)
{
setMute(speakerIP, !getMute(speakerIP));
}
void SonosUPnP::toggleLoudness(IPAddress speakerIP)
{
setLoudness(speakerIP, !getLoudness(speakerIP));
}
// JV
// New function : fill Sonmosionfo Structure with info
// 1. use parse HTTP:/[ip.nu.mb.er]:1400/status/zp command -
// 2.
SonosInfo SonosUPnP::getSonosInfo(IPAddress speakerIP)
{ SonosInfo ZP;
UID_BUFFER[0]=0;SERIAL_BUFFER[0]=0;SERIESID_BUFFER[0]=0;ZONE_BUFFER[0]=0;MEDIUM_BUFFER[0]=0;STATUS_BUFFER[0]=0;PLAYMODE_BUFFER[0]=0;SOURCE_BUFFER[0]=0; // set all buffers to terminated 0 string
// initialize ZP just to be safe
ZP.uid = UID_BUFFER;
ZP.serial = SERIAL_BUFFER;
ZP.seriesid = SERIESID_BUFFER;
ZP.zone = ZONE_BUFFER;
ZP.medium = MEDIUM_BUFFER;
ZP.status = STATUS_BUFFER;
ZP.playmode = PLAYMODE_BUFFER;
ZP.source = SOURCE_BUFFER;
if (upnpGetzp(speakerIP) ) // check if speaker is there
{ //tft.print("PARSE:");tft.println(speakerIP);
xPath.reset();
char infoBuffer[20] = "";
// Zone Info
ZP.zone = ZONE_BUFFER;
PGM_P zpath[] = { p_ZPSupportInfo, p_ZPInfo, p_ZPZone};
ethClient_xPath(zpath, 3, ZONE_BUFFER, sizeof(ZONE_BUFFER));
// Local UIDInfo
ZP.uid = UID_BUFFER;
PGM_P ypath[] = { p_ZPSupportInfo, p_ZPInfo, p_ZPLocalUID};
ethClient_xPath(ypath, 3, UID_BUFFER, sizeof(UID_BUFFER));
// Serial Info
ZP.serial = SERIAL_BUFFER;
PGM_P xpath[] = { p_ZPSupportInfo, p_ZPInfo, p_ZPSerial};
ethClient_xPath(xpath, 3, SERIAL_BUFFER, sizeof(SERIAL_BUFFER));
// Series Info
// Did not find any Series info with a ZP90 and a PLAY5 ???
ZP.seriesid = SERIESID_BUFFER;
PGM_P wpath[] = { p_ZPSupportInfo, p_ZPInfo, p_ZPSeriesID};
ethClient_xPath(wpath, 3, SERIESID_BUFFER, sizeof(SERIESID_BUFFER));
// tft.print("STAT:");tft.println(speakerIP);
getState(speakerIP,STATUS_BUFFER);
// tft.print("MED:");tft.println(speakerIP);
getMedium(speakerIP,MEDIUM_BUFFER);
// tft.print("SRC:");tft.println(speakerIP);
getSource(speakerIP,SOURCE_BUFFER);
//tft.print("PM:");tft.println(speakerIP);
getPlayMode(speakerIP,PLAYMODE_BUFFER);
}
ethClient_stop();
// tft.print("STAT:");tft.println(speakerIP);
// getState(speakerIP,STATUS_BUFFER);
// tft.print("MED:");tft.println(speakerIP);
// getMedium(speakerIP,MEDIUM_BUFFER);
// tft.print("SRC:");tft.println(speakerIP);
// getSource(speakerIP,SOURCE_BUFFER);
// tft.print("PM:");tft.println(speakerIP);
// getPlayMode(speakerIP,PLAYMODE_BUFFER);
return ZP;
}
uint8_t SonosUPnP::getState(IPAddress speakerIP)
{
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetTransportInfoR, p_CurrentTransportState };
// { p_SoapEnvelope, p_SoapBody, p_GetTransportInfoR, p_CurrentSpeed };
char result[sizeof(SONOS_STATE_PAUSED_VALUE)] = "";
upnpGetString(speakerIP, UPNP_AV_TRANSPORT, p_GetTransportInfoA, "", "", path, 4, result, sizeof(result));
return convertState(result);
}
uint8_t SonosUPnP::getState(IPAddress speakerIP,char *buf) // New JV : string passthrough
{
int t;
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetTransportInfoR, p_CurrentTransportState };
char result[16] = "\0";
upnpGetString(speakerIP, UPNP_AV_TRANSPORT, p_GetTransportInfoA, "", "", path, 4, result, sizeof(result));
if(result[0]!=0) {
for (t=0;result[t]!=0;++t) buf[t]=result[t];
buf[t]=0;
return convertState(result);
}
buf[0]=0; return 0;
}
uint8_t SonosUPnP::getMedium(IPAddress speakerIP) // New JV Medium state
{
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetMediaInfoR, p_CurrentMedium };
char result[16] = "\0";
upnpGetString(speakerIP, UPNP_AV_TRANSPORT, p_GetMediaInfoA, "", "", path, 4, result, sizeof(result));
return convertMedium(result);
}
uint8_t SonosUPnP::getMedium(IPAddress speakerIP,char *buf) // New JV Medium with string passthrough
{
int t;
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetMediaInfoR, p_CurrentMedium };
char result[16] = "\0";
upnpGetString(speakerIP, UPNP_AV_TRANSPORT, p_GetMediaInfoA, "", "", path, 4, result, sizeof(result));
//Serial.print(" /1 ");Serial.println(result);
if(result[0]!=0) {
for (t=0;result[t]!=0;++t) buf[t]=result[t];
buf[t]=0;
return convertMedium(result);
}
buf[0]=0; return 0;
}
bool SonosUPnP::getZone(IPAddress speakerIP,char *buf) // New JV : string passthrough
{
int t;
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetZoneAttributesR, p_ZoneName };
char result[32] = "\0";
upnpGetString(speakerIP, UPNP_DEVICE_PROPERTIES, p_GetZoneAttributesA, "", "", path, 4, result, sizeof(result));
if(result[0]!=0) {
for (t=0;result[t]!=0;++t) buf[t]=result[t];
buf[t]=0;
return 1;
}
buf[0]=0; return 0;
}
bool SonosUPnP::getSerial(IPAddress speakerIP,char *buf) // New JV : string passthrough
{
int t;
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetZoneInfoR, p_Serial };
char result[20] = "\0";
upnpGetString(speakerIP, UPNP_DEVICE_PROPERTIES, p_GetZoneInfoA, "", "", path, 4, result, sizeof(result));
if(result[0]!=0) {
for (t=0;result[t]!=0;++t) buf[t]=result[t];
buf[t]=0;
return 1;
}
buf[0]=0; return 0;
}
uint8_t SonosUPnP::getPlayMode(IPAddress speakerIP,char *buf) // New JV : string passthrough
{
int t;
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetTransportSettingsR, p_PlayMode };
char result[16] = "\0";
upnpGetString(speakerIP, UPNP_AV_TRANSPORT, p_GetTransportSettingsA, "", "", path, 4, result, sizeof(result));
if(result[0]!=0) {
for (t=0;result[t]!=0;++t) buf[t]=result[t];
buf[t]=0;
return convertPlayMode(result);
}
buf[0]=0; return 0;
}
uint8_t SonosUPnP::getPlayMode(IPAddress speakerIP)
{
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetTransportSettingsR, p_PlayMode };
char result[sizeof(SONOS_PLAY_MODE_SHUFFLE_VALUE)] = "";
upnpGetString(speakerIP, UPNP_AV_TRANSPORT, p_GetTransportSettingsA, "", "", path, 4, result, sizeof(result));
return convertPlayMode(result);
}
bool SonosUPnP::getRepeat(IPAddress speakerIP)
{
return getPlayMode(speakerIP) & SONOS_PLAY_MODE_REPEAT;
}
bool SonosUPnP::getShuffle(IPAddress speakerIP)
{
return getPlayMode(speakerIP) & SONOS_PLAY_MODE_SHUFFLE;
}
TrackInfo SonosUPnP::getTrackInfo(IPAddress speakerIP, char *uriBuffer, size_t uriBufferSize, char *metaBuffer, size_t metaBufferSize)
{
TrackInfo trackInfo;
if (upnpPost(speakerIP, UPNP_AV_TRANSPORT, p_GetPositionInfoA, "", "", "", 0, 0, ""))
{
xPath.reset();
char infoBuffer[20] = "";
// Track number
PGM_P npath[] = { p_SoapEnvelope, p_SoapBody, p_GetPositionInfoR, p_Track };
ethClient_xPath(npath, 4, infoBuffer, sizeof(infoBuffer));
trackInfo.number = atoi(infoBuffer);
// Track duration
PGM_P dpath[] = { p_SoapEnvelope, p_SoapBody, p_GetPositionInfoR, p_TrackDuration };
ethClient_xPath(dpath, 4, infoBuffer, sizeof(infoBuffer));
trackInfo.duration = getTimeInSeconds(infoBuffer);
// en hoe zit het met <TrackMetaData>[Meta data in DIDL-Lite]</TrackMetaData> een broddelwerkje van Frank - 21-5-2020
PGM_P mpath[] = { p_SoapEnvelope, p_SoapBody, p_GetPositionInfoR, p_TrackMetaData };
ethClient_xPath(mpath, 4, metaBuffer, metaBufferSize);
trackInfo.trackmetadata = metaBuffer;
// Track URI
PGM_P upath[] = { p_SoapEnvelope, p_SoapBody, p_GetPositionInfoR, p_TrackURI };
ethClient_xPath(upath, 4, uriBuffer, uriBufferSize);
trackInfo.uri = uriBuffer;
// Track position
PGM_P ppath[] = { p_SoapEnvelope, p_SoapBody, p_GetPositionInfoR, p_RelTime };
ethClient_xPath(ppath, 4, infoBuffer, sizeof(infoBuffer));
trackInfo.position = getTimeInSeconds(infoBuffer);
}
ethClient_stop();
return trackInfo;
}
uint16_t SonosUPnP::getTrackNumber(IPAddress speakerIP)
{
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetPositionInfoR, p_Track };
char result[6] = "0";
upnpGetString(speakerIP, UPNP_AV_TRANSPORT, p_GetPositionInfoA, "", "", path, 4, result, sizeof(result));
return atoi(result);
}
void SonosUPnP::getTrackURI(IPAddress speakerIP, char *resultBuffer, size_t resultBufferSize)
{
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetPositionInfoR, p_TrackURI };
upnpGetString(speakerIP, UPNP_AV_TRANSPORT, p_GetPositionInfoA, "", "", path, 4, resultBuffer, resultBufferSize);
}
uint8_t SonosUPnP::getSourceFromURI(const char *uri) // adapted JV
{
uint8_t t,v;
// Serial.println(uri);
for (t=0;t<SONOS_MAXSOURCE;++t)
{
v=0;
while (p_MediaSource[t][v] !=0)
{
if (p_MediaSource[t][v]!=uri[v]) break;
v++;
}
if(p_MediaSource[t][v]==0 ) return t; // we have a match
}
return(0);
}
//uint8_t SonosUPnP::getSource(IPAddress speakerIP)
//{
// char uri[25] = "";
// getTrackURI(speakerIP, uri, sizeof(uri));
// return getSourceFromURI(uri);
//}
uint8_t SonosUPnP::getSource(IPAddress speakerIP) // adapted JV
{
uint8_t t,v;
char uri[32] = "";
getTrackURI(speakerIP, uri, sizeof(uri));
for (t=0;t<SONOS_MAXSOURCE;++t)
{
v=0;
while (p_MediaSource[t][v] !=0)
{
if (p_MediaSource[t][v]!=uri[v]) break;
v++;
}
if(p_MediaSource[t][v]==0 ) return t; // we have a match
}
return(0);
}
uint8_t SonosUPnP::getSource(IPAddress speakerIP,char *buf) // new JV
{
uint8_t t,u,v;
char uri[32] = "";
getTrackURI(speakerIP, uri, sizeof(uri));
for (t=0;t<SONOS_MAXSOURCE;++t)
{
v=0;
while (p_MediaSource[t][v] !=0)
{
if (p_MediaSource[t][v]!=uri[v]) break;
v++;
}
if(p_MediaSource[t][v]==0 ) // we have a match
{
for (u=0; p_MediaSourceName[t][u]!=0 ;u++ ) buf[u]=p_MediaSourceName[t][u]; // copy name to buffer
buf[u]=0; // end buffer with zero
return t;
}
}
buf[0]=0; // make empty buffer string
return(0);
}
uint32_t SonosUPnP::getTrackDurationInSeconds(IPAddress speakerIP)
{
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetPositionInfoR, p_TrackDuration };
char result[20] = "";
upnpGetString(speakerIP, UPNP_AV_TRANSPORT, p_GetPositionInfoA, "", "", path, 4, result, sizeof(result));
return getTimeInSeconds(result);
}
uint32_t SonosUPnP::getTrackPositionInSeconds(IPAddress speakerIP)
{
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetPositionInfoR, p_RelTime };
char result[20] = "";
upnpGetString(speakerIP, UPNP_AV_TRANSPORT, p_GetPositionInfoA, "", "", path, 4, result, sizeof(result));
return getTimeInSeconds(result);
}
uint16_t SonosUPnP::getTrackPositionPerMille(IPAddress speakerIP)
{
uint16_t perMille = 0;
if (upnpPost(speakerIP, UPNP_AV_TRANSPORT, p_GetPositionInfoA, "", "", "", 0, 0, ""))
{
char result[20];
xPath.reset();
PGM_P dpath[] = { p_SoapEnvelope, p_SoapBody, p_GetPositionInfoR, p_TrackDuration };
ethClient_xPath(dpath, 4, result, sizeof(result));
uint32_t duration = getTimeInSeconds(result);
PGM_P ppath[] = { p_SoapEnvelope, p_SoapBody, p_GetPositionInfoR, p_RelTime };
ethClient_xPath(ppath, 4, result, sizeof(result));
uint32_t position = getTimeInSeconds(result);
if (duration && position)
{
perMille = (position * 1000) / duration;
}
}
ethClient_stop();
return perMille;
}
bool SonosUPnP::getMute(IPAddress speakerIP)
{
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetMuteR, p_CurrentMute };
char result[3] = "0";
upnpGetString(
speakerIP, UPNP_RENDERING_CONTROL, p_GetMuteA,
SONOS_TAG_CHANNEL, SONOS_CHANNEL_MASTER, path, 4, result, sizeof(result));
return strcmp(result, "1") == 0;
}
uint8_t SonosUPnP::getVolume(IPAddress speakerIP)
{
return getVolume(speakerIP, SONOS_CHANNEL_MASTER);
}
//int8_t SonosUPnP::getVolume(IPAddress speakerIP, const char *channel)
//{
// PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetVolumeR, p_CurrentVolume };
// char result[5] = "0";
// if( upnpGetString(
// speakerIP, UPNP_RENDERING_CONTROL, p_GetVolumeA,
// SONOS_TAG_CHANNEL, channel, path, 4, result, sizeof(result)) )
// { // succesvolle read
// return constrain(atoi(result), 0, 100);
// }
// getvolume mislukt
// return -1;
//}
uint8_t SonosUPnP::getVolume(IPAddress speakerIP, const char *channel)
{
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetVolumeR, p_CurrentVolume };
char result[5] = "0";
upnpGetString(
speakerIP, UPNP_RENDERING_CONTROL, p_GetVolumeA,
SONOS_TAG_CHANNEL, channel, path, 4, result, sizeof(result));
return constrain(atoi(result), 0, 100);
}
bool SonosUPnP::getOutputFixed(IPAddress speakerIP)
{
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetOutputFixedR, p_CurrentFixed };
char result[3] = "0";
upnpGetString(speakerIP, UPNP_RENDERING_CONTROL, p_GetOutputFixedA, "", "", path, 4, result, sizeof(result));
return strcmp(result, "1") == 0;
}
int8_t SonosUPnP::getBass(IPAddress speakerIP)
{
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetBassR, p_CurrentBass };
char result[5] = "0";
upnpGetString(
speakerIP, UPNP_RENDERING_CONTROL, p_GetBassA,
SONOS_TAG_CHANNEL, SONOS_CHANNEL_MASTER, path, 4, result, sizeof(result));
return constrain(atoi(result), -10, 10);
}
int8_t SonosUPnP::getTreble(IPAddress speakerIP)
{
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetTrebleR, p_CurrentTreble };
char result[5] = "0";
upnpGetString(
speakerIP, UPNP_RENDERING_CONTROL, p_GetTrebleA,
SONOS_TAG_CHANNEL, SONOS_CHANNEL_MASTER, path, 4, result, sizeof(result));
return constrain(atoi(result), -10, 10);
}
bool SonosUPnP::getLoudness(IPAddress speakerIP)
{
PGM_P path[] = { p_SoapEnvelope, p_SoapBody, p_GetLoudnessR, p_CurrentLoudness };
char result[3] = "0";
upnpGetString(
speakerIP, UPNP_RENDERING_CONTROL, p_GetLoudnessA,
SONOS_TAG_CHANNEL, SONOS_CHANNEL_MASTER, path, 4, result, sizeof(result));
return strcmp(result, "1") == 0;
}
#endif
void SonosUPnP::seek(IPAddress speakerIP, const char *mode, const char *data)
{
upnpSet(
speakerIP, UPNP_AV_TRANSPORT, p_Seek,
SONOS_TAG_TARGET, data, "", p_SeekModeTagStart, p_SeekModeTagEnd, mode);
}
void SonosUPnP::setAVTransportURI(IPAddress speakerIP, const char *scheme, const char *address, PGM_P metaStart_P, PGM_P metaEnd_P, const char *metaValue)
{
// Info to show in player, in DIDL format, can be added as META data
upnpSet(
speakerIP, UPNP_AV_TRANSPORT, p_SetAVTransportURI,
SONOS_TAG_CURRENT_URI, scheme, address, metaStart_P, metaEnd_P, metaValue);
}
void SonosUPnP::upnpSet(IPAddress ip, uint8_t upnpMessageType, PGM_P action_P)
{
upnpSet(ip, upnpMessageType, action_P, "", "");
}
void SonosUPnP::upnpSet(IPAddress ip, uint8_t upnpMessageType, PGM_P action_P, const char *field, const char *value)
{
upnpSet(ip, upnpMessageType, action_P, field, value, "", 0, 0, "");
}
void SonosUPnP::upnpSet(IPAddress ip, uint8_t upnpMessageType, PGM_P action_P, const char *field, const char *valueA, const char *valueB, PGM_P extraStart_P, PGM_P extraEnd_P, const char *extraValue)
{
upnpPost(ip, upnpMessageType, action_P, field, valueA, valueB, extraStart_P, extraEnd_P, extraValue);
ethClient_stop();
}
bool SonosUPnP::upnpGetzp(IPAddress ip) // JV new - simple GET status/zp command
{ // tft.print("Getzp:");tft.println(ip);
if (!ethClient.connect(ip, UPNP_PORT))
{ // tft.print("Return Getzp F");tft.println(ip);
return false;
}
char buffer[50];
ethClient_write("GET /status/zp HTTP/1.1\n");
sprintf_P(buffer, p_HeaderHost, ip[0], ip[1], ip[2], ip[3], UPNP_PORT); // 29 bytes max
ethClient_write(buffer);
ethClient_write("Connection: close\n");
ethClient_write("\n");
//tft.print("WAIT:");tft.println(ip);
uint32_t start = millis();
while (!ethClient.available())
{
if (millis() > (start + UPNP_RESPONSE_TIMEOUT_MS))
{
//if (ethernetErrCallback) ethernetErrCallback();
return false;
}
}
return true;
}
bool SonosUPnP::upnpPost(IPAddress ip, uint8_t upnpMessageType, PGM_P action_P, const char *field, const char *valueA, const char *valueB, PGM_P extraStart_P, PGM_P extraEnd_P, const char *extraValue)
{
if (!ethClient.connect(ip, UPNP_PORT))
{ if (ethernetErrCallback) ethernetErrCallback();
return false;
}
Serial.print("*SONOS:");
// Get UPnP service name
PGM_P upnpService = getUpnpService(upnpMessageType);
// Get HTTP content/body length
uint16_t contentLength =
sizeof(SOAP_ENVELOPE_START) - 1 +
sizeof(SOAP_BODY_START) - 1 +
SOAP_ACTION_TAG_LEN +
(strlen_P(action_P) * 2) +
sizeof(UPNP_URN_SCHEMA) - 1 +
strlen_P(upnpService) +
sizeof(SONOS_INSTANCE_ID_0_TAG) - 1 +
sizeof(SOAP_BODY_END) - 1 +
sizeof(SOAP_ENVELOPE_END) - 1;
// Get length of field
uint8_t fieldLength = strlen(field);
if (fieldLength)
{
contentLength +=
SOAP_TAG_LEN +
(fieldLength * 2) +
strlen(valueA) +
strlen(valueB);
}
// Get length of extra field data (e.g. meta data fields)
if (extraStart_P)
{
contentLength +=
strlen_P(extraStart_P) +
strlen(extraValue) +
strlen_P(extraEnd_P);
}
char buffer[1400];
// Write HTTP start