Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
qos-1pub_extended.c
00001 /******************************************************************************* 00002 * Copyright (c) 2014 IBM Corp. 00003 * 00004 * All rights reserved. This program and the accompanying materials 00005 * are made available under the terms of the Eclipse Public License v1.0 00006 * and Eclipse Distribution License v1.0 which accompany this distribution. 00007 * 00008 * The Eclipse Public License is available at 00009 * http://www.eclipse.org/legal/epl-v10.html 00010 * and the Eclipse Distribution License is available at 00011 * http://www.eclipse.org/org/documents/edl-v10.php. 00012 * 00013 * Contributors: 00014 * Ian Craggs - initial API and implementation and/or initial documentation 00015 * Sergio R. Caprile - clarifications and/or documentation extension 00016 * 00017 * Description: 00018 * Extension to the specs in which a node can send a normal (long) topic name inside the 00019 * payload area to avoid the registration process and the usage of short/predefined types 00020 *******************************************************************************/ 00021 00022 #include <stdio.h> 00023 #include <string.h> 00024 #include <stdlib.h> 00025 00026 #include "MQTTSNPacket.h" 00027 #include "transport.h" 00028 00029 00030 int main(int argc, char** argv) 00031 { 00032 int rc = 0; 00033 int mysock; 00034 unsigned char buf[200]; 00035 int buflen = sizeof(buf); 00036 MQTTSN_topicid topic; 00037 unsigned char* payload = (unsigned char*)"mypayload"; 00038 int payloadlen = strlen((char*)payload); 00039 int len = 0; 00040 int dup = 0; 00041 int qos = 3; 00042 int retained = 0; 00043 short packetid = 0; 00044 char *topicname = "a long topic name"; 00045 char *host = "127.0.0.1"; 00046 int port = 1883; 00047 00048 mysock = transport_open(); 00049 if(mysock < 0) 00050 return mysock; 00051 00052 if (argc > 1) 00053 host = argv[1]; 00054 00055 if (argc > 2) 00056 port = atoi(argv[2]); 00057 00058 printf("Sending to hostname %s port %d\n", host, port); 00059 00060 topic.type = MQTTSN_TOPIC_TYPE_NORMAL; 00061 topic.data.long_.name = topicname; 00062 topic.data.long_.len = strlen(topicname); 00063 00064 len = MQTTSNSerialize_publish(buf, buflen, dup, qos, retained, packetid, 00065 topic, payload, payloadlen); 00066 00067 rc = transport_sendPacketBuffer(host, port, buf, len); 00068 00069 transport_close(); 00070 00071 return 0; 00072 }
Generated on Mon Feb 13 2023 09:41:23 by
1.7.2