| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- /*
- The MIT License(MIT)
- Cayenne Arduino Client Library
- Copyright © 2016 myDevices
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
- documentation files(the "Software"), to deal in the Software without restriction, including without limitation
- the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software,
- and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- This software uses open source blynk-library - see blynk-library/LICENSE
- */
- #ifndef _CAYENNEETHERNETCLIENT_h
- #define _CAYENNEETHERNETCLIENT_h
- #include "CayenneClient.h"
- class CayenneEthernetClient : public CayenneClient
- {
- public:
- /**
- * Begins Cayenne session
- * @param token Authentication token from Cayenne site
- * @param mac Mac address for device
- */
- void begin(const char* token, const byte mac[] = NULL)
- {
- Blynk.begin(token, CAYENNE_DOMAIN, CAYENNE_PORT, GetMACAddress(token, mac));
- }
- /**
- * Begins Cayenne session
- * @param token Authentication token from Cayenne site
- * @param local Static IP address of device
- * @param mac Mac address for device
- */
- void begin(const char* token, IPAddress local, const byte mac[] = NULL)
- {
- Blynk.begin(token, CAYENNE_DOMAIN, CAYENNE_PORT, local, GetMACAddress(token, mac));
- }
- /**
- * Begins Cayenne session
- * @param token Authentication token from Cayenne site
- * @param local Static IP address of device
- * @param dns IP address of DNS server
- * @param gateway IP address of gateway
- * @param subnet Subnet mask
- * @param mac Mac address for device
- */
- void begin(const char* token, IPAddress local, IPAddress dns, IPAddress gateway, IPAddress subnet, const byte mac[] = NULL)
- {
- Blynk.begin(token, CAYENNE_DOMAIN, CAYENNE_PORT, local, dns, gateway, subnet, GetMACAddress(token, mac));
- }
- private:
- /**
- * Get MAC address fror the device
- * @param token Authentication token from Cayenne site
- * @param mac User defined mac address for device
- * @returns Mac address for device
- */
- const byte* GetMACAddress(const char* token, const byte mac[])
- {
- if (mac != NULL)
- return mac;
- _mac[0] = 0xFE;
- if (strnlen(token, 10) != 10)
- {
- CAYENNE_LOG("Using default MAC");
- _mac[1] = 0xED;
- _mac[2] = 0xBA;
- _mac[3] = 0xFE;
- _mac[4] = 0xFE;
- _mac[5] = 0xED;
- }
- else
- {
- //Generate MAC from token to prevent collisions on the same network.
- _mac[1] = token[0] + token[1];
- _mac[2] = token[2] + token[3];
- _mac[3] = token[4] + token[5];
- _mac[4] = token[6] + token[7];
- _mac[5] = token[8] + token[9];
- }
- CAYENNE_LOG("MAC: %X-%X-%X-%X-%X-%X", _mac[0], _mac[1], _mac[2], _mac[3], _mac[4], _mac[5]);
- return _mac;
- }
- byte _mac[6];
- };
- CayenneEthernetClient Cayenne;
- #endif
|