hellomqttt to thingspeak mqtt and ifttt

Dependencies:   Servo MQTTPacket FP

Committer:
jasonberry
Date:
Wed May 05 14:48:01 2021 +0000
Revision:
25:ca1b1098c77f
TEST

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jasonberry 25:ca1b1098c77f 1 /*
jasonberry 25:ca1b1098c77f 2 * Copyright (c) 2016-2016 ARM Limited. All rights reserved.
jasonberry 25:ca1b1098c77f 3 * SPDX-License-Identifier: Apache-2.0
jasonberry 25:ca1b1098c77f 4 * Licensed under the Apache License, Version 2.0 (the License); you may
jasonberry 25:ca1b1098c77f 5 * not use this file except in compliance with the License.
jasonberry 25:ca1b1098c77f 6 * You may obtain a copy of the License at
jasonberry 25:ca1b1098c77f 7 *
jasonberry 25:ca1b1098c77f 8 * http://www.apache.org/licenses/LICENSE-2.0
jasonberry 25:ca1b1098c77f 9 *
jasonberry 25:ca1b1098c77f 10 * Unless required by applicable law or agreed to in writing, software
jasonberry 25:ca1b1098c77f 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
jasonberry 25:ca1b1098c77f 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
jasonberry 25:ca1b1098c77f 13 * See the License for the specific language governing permissions and
jasonberry 25:ca1b1098c77f 14 * limitations under the License.
jasonberry 25:ca1b1098c77f 15 */
jasonberry 25:ca1b1098c77f 16 #include "at24mac.h"
jasonberry 25:ca1b1098c77f 17
jasonberry 25:ca1b1098c77f 18 /* Device addressing */
jasonberry 25:ca1b1098c77f 19 #define AT24MAC_EEPROM_ADDRESS (0x0A<<4)
jasonberry 25:ca1b1098c77f 20 #define AT24MAC_RW_PROTECT_ADDRESS (0x06<<4)
jasonberry 25:ca1b1098c77f 21 #define AT24MAC_SERIAL_ADDRESS (0x0B<<4)
jasonberry 25:ca1b1098c77f 22
jasonberry 25:ca1b1098c77f 23 /* Known memory blocks */
jasonberry 25:ca1b1098c77f 24 #define AT24MAC_SERIAL_OFFSET (0x80)
jasonberry 25:ca1b1098c77f 25 #define AT24MAC_EUI64_OFFSET (0x98)
jasonberry 25:ca1b1098c77f 26 #define AT24MAC_EUI48_OFFSET (0x9A)
jasonberry 25:ca1b1098c77f 27
jasonberry 25:ca1b1098c77f 28 #define SERIAL_LEN 16
jasonberry 25:ca1b1098c77f 29 #define EUI64_LEN 8
jasonberry 25:ca1b1098c77f 30 #define EUI48_LEN 6
jasonberry 25:ca1b1098c77f 31
jasonberry 25:ca1b1098c77f 32 AT24Mac::AT24Mac(PinName sda, PinName scl) : _i2c(sda, scl)
jasonberry 25:ca1b1098c77f 33 {
jasonberry 25:ca1b1098c77f 34 // Do nothing
jasonberry 25:ca1b1098c77f 35 }
jasonberry 25:ca1b1098c77f 36
jasonberry 25:ca1b1098c77f 37 int AT24Mac::read_serial(void *buf)
jasonberry 25:ca1b1098c77f 38 {
jasonberry 25:ca1b1098c77f 39 char offset = AT24MAC_SERIAL_OFFSET;
jasonberry 25:ca1b1098c77f 40 if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true))
jasonberry 25:ca1b1098c77f 41 return -1; //No ACK
jasonberry 25:ca1b1098c77f 42 return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char*)buf, SERIAL_LEN);
jasonberry 25:ca1b1098c77f 43 }
jasonberry 25:ca1b1098c77f 44
jasonberry 25:ca1b1098c77f 45 int AT24Mac::read_eui64(void *buf)
jasonberry 25:ca1b1098c77f 46 {
jasonberry 25:ca1b1098c77f 47 char offset = AT24MAC_EUI64_OFFSET;
jasonberry 25:ca1b1098c77f 48 if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true))
jasonberry 25:ca1b1098c77f 49 return -1; //No ACK
jasonberry 25:ca1b1098c77f 50 return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char*)buf, EUI64_LEN);
jasonberry 25:ca1b1098c77f 51 }
jasonberry 25:ca1b1098c77f 52
jasonberry 25:ca1b1098c77f 53 int AT24Mac::read_eui48(void *buf)
jasonberry 25:ca1b1098c77f 54 {
jasonberry 25:ca1b1098c77f 55 char offset = AT24MAC_EUI48_OFFSET;
jasonberry 25:ca1b1098c77f 56 if (_i2c.write(AT24MAC_SERIAL_ADDRESS, &offset, 1, true))
jasonberry 25:ca1b1098c77f 57 return -1; //No ACK
jasonberry 25:ca1b1098c77f 58 return _i2c.read(AT24MAC_SERIAL_ADDRESS, (char*)buf, EUI48_LEN);
jasonberry 25:ca1b1098c77f 59 }